Forum Discussion

BarryDolan's avatar
BarryDolan
Qrew Cadet
9 months ago

Inconsistent results using this API_EditRecord

I have a form setup with buttons that capture the current time on a button click. It works great using both a code page or just running the code in the URL formula field. But I've found an issue that I can't seem to find a solution for. Maybe it's with the code, or maybe it's something else entirely.

I found this code in the Magic Buttons app and tweaked it a little for our purposes.

var text urlToExecute = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=APP_TOKEN" & "&rid=" & [Record ID#] & "&_fid_62="&ToTimeOfDay(Now());

URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=56" & "&url=" & URLEncode($urlToExecute)

--------------------------

I've also used this successfully without calling the code page;

URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=APP_TOKEN" 
& "&rid=" & [Record ID#] & "&_fid_62="&ToTimeOfDay(Now())

--------------------------

The issue I'm having is after I use one button to run the code and update the field with the current time, I'll wait for a period of time, several minutes or a few hours, then I click a different button coded the same but with a different field id, and it populates the field with the same time from the first button click, not the current time. It acts like it ignores the Now() function and uses the last time from memory, or something like that. But when I click it again it works correctly.

I was also able to duplicate the same results in the Magic Button app by setting up a second button and text field. I hit the second button and it put the same time, not the current time, in the other field. 

This seems like a refresh issue. If I manually refresh the page before clicking the next button I get the current time. So I tried appending code to refresh the page. 

& "&rdr=" & URLEncode(URLRoot() & "db/" &Dbid() & "?a=dr&rid=" & [Record ID#])

That didn't work, so I tried appending code to redirect to a table report 

& "&rdr=" & URLEncode(URLRoot() & "db/" &Dbid() & "?a=q&qid=8")

No good there either. I tried the app's home page

& "&rdr=" & URLEncode(URLRoot() & "db/" & AppID()),

no success. No matter what I do, short of logging out and back in, or a manual refresh, it will still use the same time that it previously used.

This is all from a desktop using Chrome. I can duplicate it in other browsers, and it behaves the same using the mobile app.

I would appreciate any insight into this issue. It just makes no sense why it would be using the same time when it's calling the Now() function.



------------------------------
Barry Dolan
------------------------------

7 Replies

  • I tried to replicate this behavior, but could not. This is what I did:

    [Set Time 1] = 

    var text urlToExecute = 
    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord &apptoken=xxxx" &
    "&rid=" & [Record ID#] & "&_fid_30="&ToTimeOfDay(Now());

    $URLtoExecute

    [Set Time 2] = 

    var text urlToExecute = 
    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord &apptoken=xxxx" &
    "&rid=" & [Record ID#] & "&_fid_31="&ToTimeOfDay(Now());

    $URLtoExecute

    Is this a correct test to duplicate your scenario?  I didnt even have it return anywhere. Field 30 and 31 are time of day fields.



    ------------------------------
    Mike Tamoush
    ------------------------------
    • BarryDolan's avatar
      BarryDolan
      Qrew Cadet

      I tried using Time of Day field type but I get the same behavior



      ------------------------------
      Barry Dolan
      ------------------------------
  • Is there any particular reason in your first example you're using the code page at all? Is there another process that you're running or do you just need the button to log the current time and then refresh the page? If that's the case then you can just do a button like this: 

    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=APP_TOKEN" 
    & "&rid=" & [Record ID#] & "&_fid_62="&ToTimeOfDay(Now()) & "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=DoRedirect&z=" & Rurl()) 

    This will just do the editRecord and then refresh the page your on. It sounds like some of your issues relate to the state of the browser page and the page/document not reloading based on how you're currently navigating in the app, so having the button just do a simple refresh should solve for it so that the button refreshes it's own components/reloads the idea of now() for your use. 



    ------------------------------
    Chayce Duncan
    ------------------------------
    • TimD's avatar
      TimD
      Qrew Trainee

      you can also just do URLEncode("today") so you dont have to refresh even if you've been on the page for a while, it will take the system's time... found it in this forum somewhere so credit goes to that person



      ------------------------------
      Tim D
      ------------------------------
      • BarryDolan's avatar
        BarryDolan
        Qrew Cadet

        humm, that just put the word "today" in the field.

        I'm trying



        ------------------------------
        Barry Dolan
        ------------------------------
    • BarryDolan's avatar
      BarryDolan
      Qrew Cadet

      I began using the code page because that's how it was in the Magic Buttons app, but since I've found that I didn't need that, I disable the code page. 

      As, as in my explanation, I tried using refresh with this: & "&rdr=" & URLEncode(URLRoot() & "db/" &Dbid() & "?a=dr&rid=" & [Record ID#])

      I didn't have any success using "?a=DoRedirect&z=" & Rurl()) 

      A hard refresh is the only thing that seems to make a difference.



      ------------------------------
      Barry Dolan
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend

        Barry

        I'd you were populating a date/time field in this syntax populate the field with the date/time when the page loaded. 

        "&_fid_99=" & Now()

        However, this improved syntax below will populate field 99 with the current date and time when the button is pushed.

        &_fid_99=now

        If your issue is that the button is getting stale while sitting on the screen, for example, if you were designing a time, clock application, where employees punch in and out, then you want to know when the button is pushed.


        So my suggestion is use that syntax to populate the date/time field and then use a different formula field to extract out just the time of day portion of that field.



        ------------------------------
        Mark Shnier (Your Quickbase Coach)
        mark.shnier@gmail.com
        ------------------------------