Forum Discussion

EOMDevelepors's avatar
EOMDevelepors
Qrew Captain
7 years ago

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

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

18 Replies

  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    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.
    • EOMDevelepors's avatar
      EOMDevelepors
      Qrew Captain
      How about adding a get line of code to get the time from any given date time field in any table which I can set a formula field to be now().

      Can you help me with this line of code to get the date time from that field?

      Thanks
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    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 .
  • 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()
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      Scott, that won't work.
        
      If you did that formula and exposed the code, you would see that it is all resolved into a text string URL and the second Now() is immediately populated.

      I'm still liking the Action method, myself.  Trigger an Action to do the update if you really need the Now() time.
    • ScottMarks's avatar
      ScottMarks
      Qrew Member
      Hmm actually you're right.  My mistake.  

      Perhaps you could redirect to a code page that takes the rid url param, as well as dbid and use some javascript to run a call after the fact with the current time.

      I think that should work, I'll see if I can setup a demo. 
    • ScottMarks's avatar
      ScottMarks
      Qrew Member
      Alright, so to start this method off...

      You will need the following code page:

      <HTML> <HEAD> <title>Refresh Time</title> <script type="text/javascript">  var urlParam = function(name, w){     w = w || window;     var rx = new RegExp('[\&|\?]'+name+'=([^\&\#]+)'),         val = w.location.search.match(rx);     return !val ? '':val[1]; }  var dbid = urlParam('dbid'); var rid = urlParam('rid'); var fid = urlParam('fid'); var token = "YOUR TOKEN HERE"; var base_url = window.location.origin; var date = new Date;    function refresh(){      window.location.replace(base_url + "/db/" + dbid + "?a=API_EditRecord&rid=" + rid + "&apptoken=" + token + "&_fid_" + fid + "=" + date); }   </script>   </HEAD>  <BODY>   <script>refresh()</script>  </BODY> </HTML>

      Lastly, you will need to format your INITIAL API call to redirect to this page. 

      As said in a previous post, it'll be something like this:
      URLRoot()&"db/"&Dbid()&"?a=API_EditRecord&rid="&[Record ID#]&"&apptoken=xxxxxxx&<DO YOUR STUFF HERE FIRST>&"&rdr=<LINK TO NEW .HTML CODE PAGE WITH SCRIPT>&rid="&[Record ID]&"dbid="&Dbid()&"fid=<YOUR FID HERE>&rdr="&<YOUR FINAL REDIRECT LINK>

      After you sift through and correct the inevitable syntax errors, and probably adjust the Javascript Date function to output correctly for QB formatting, this should solve your issue. 

      Scott
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    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.
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    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.