Discussions

 View Only
Expand all | Collapse all

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

EOM Develepors

EOM Develepors05-22-2018 17:06

EOM Develepors

EOM Develepors05-22-2018 19:42

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

    Posted 05-18-2018 21:02
    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


  • 2.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-18-2018 23:39
    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.


  • 3.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-20-2018 21:15
    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.


  • 4.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 17:05
    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


  • 5.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 17:06
    Thanks for your reply.


  • 6.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-21-2018 12:34
    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 .


  • 7.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 17:06
    Thanks for your reply.


  • 8.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 17:06
    Today won't help me since I need the time as well...


  • 9.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 17:14
    Today does put the time in as well when used like I showed.


  • 10.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 18:40
    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()


  • 11.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 18:45
    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.


  • 12.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 18:50
    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. 


  • 13.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:17
    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


  • 14.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:19
    That said, the action trigger method is much simpler.  :^)

    EDIT: And you can actually skip the JS date function, and just use "=Now()" at the end of the redirect in the code page instead of the "=" + date piece.  Derp.


  • 15.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:06
    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");


  • 16.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:42
    This worked like a charm. Thanks so much.


  • 17.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:26
    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.


  • 18.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:34
    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.


  • 19.  RE: Refresh time before editing record with current time using the now() method.

    Posted 05-22-2018 19:44
    Thanks to everyone for replying. I really appreciate it.