Skip to main content
Question

Refresh time before editing record with current time using the now() method.

  • May 19, 2018
  • 0 replies
  • 191 views

Can anyone help me with refreshing the time before editing a record via url formula with current time being posted to end date/time field.

Here is my current code:

If(IsNull([End Date/Time]
),
var text URL =
URLRoot()
& "db/" & Dbid() & "?a
=API_EditRecord&apptoken
=[token]\n &rid=" &
[Record ID#] &
"&_fid_19="&Now();
"javascript:" &
"location.reload(true);"
&
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);"
&
"});"
& "void(0);",
"javascript:alert('You
marked this as ended
working already.')")

The problem is that if the user is currently on the page a while it will not update the current time instead it will execute with original time that the record was viewed.

Thanks

  • Registered
  • May 19, 2018
You either have to force them to refresh the page manually prior, or use a code page to 'get' the time and then write the record.

This question has been asked many times in this forum and has never really had a satisfactory answer.

But here is a low tech solution..

Instead of directly updating the date/time, use an Action or an Automation to set the current time. So the edit of a record will request that the date time be updated, rather than directly updating it.

You can do 2 of the following as well.

1. Put the word "today" in the date time field as below:
& "&_fid_645="& URLEncode("today")

2. Or you can use separate tables and take advantage of the Date Created field Kurt Trachy has an app showing how to do this. The app is ABC Tracking In/Out Time

Either way is much better than the dysfunctional Now(). Depending on the use case we alternate between the 2 methods .

  • Registered
  • May 22, 2018
You could always have your API call redirect to ANOTHER API call that then modifies the end time with Now().  That way, no matter how long someone is on the page, the Now() is always called on the second half and is always "up to date".

//First section of your API call that changes record values n such, Now() is not included in this part..
URLRoot()&"db/"&Dbid()&"?a=API_EditRecord&rid="&[Record ID#]&"&apptoken=xxxxxxx&<DO YOUR STUFF HERE FIRST>
//Second section which executes the NOW() function, which has been "refreshed" in a second api call.
&"&rdr="&URLRoot()&"db/"&Dbid()&"?a=API_EditRecord&rid="&[Record ID#]&"&apptoken=xxxxxxx&_fid_19=Now()

Did you try the following? We encountered this over a year ago with a Check-In and Out button and went through many complex solutions. Finally to our surprise putting in the word 'today' worked and we still use it today (pun intended). That reminds me to fix a button post where I was using that pesky Now().....thanks for that.


"&_fid_19="& URLEncode("today");

Jason,
Wow, that is a pretty obscure Easter egg.  I can't imagine how you found that out that works other than perhaps dumb luck and bad syntax which happened to work.

Actually it wasn't dumb luck I talked with Jeff Jones who was at the time Quick Base support and he provided the solution. We have used it thousands of times since thanks to Jeff Jones.

  • Author
  • Registered
  • May 22, 2018
Thanks to everyone for replying. I really appreciate it.