Skip to main content
Question

Inconsistent results using this API_EditRecord

  • September 11, 2023
  • 0 replies
  • 122 views

Forum|alt.badge.img+6

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
------------------------------
This topic has been closed for replies.

Forum|alt.badge.img+20
  • Registered
  • September 12, 2023

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
------------------------------

Forum|alt.badge.img+9
  • Registered
  • September 12, 2023

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
------------------------------