Forum Discussion

LuisInciarte's avatar
Qrew Member
2 years ago

How to time stamp a field using a button.

   I'm trying to create a form to audit some of our company assets(Keys). I have 3 tables called Keys, Employees and Audits.  They are properly related. 
  When I add a new Audit, I'm able to select the employee I want to audit, then I need to see a list of the assets related to this employee (for this I used a report link from the Keys table and a rich text button called StartAudit to save-and-keep-working in order to see the records on this link report). 
  In order to register the start-time of the audit, I have a Formula-Time Of Day field in the Audit table called Start Time with the line:   ToTimeOfDay([Date Created]). That works just fine.
  The problem I'm having is on how to register the End Time of the audit.
  After looking into several comments, I tried using another rich text button called Finish Audit that would change the value of the field End Time, then redirect to the same table and same record ID.
  This is not working properly since the time that is being registered as End Time is the same as the Start Time.

   Here is the formula I used on the Rich Text button (Start Audit):
var text rid = If([Record ID#]>0, ToText([Record ID#]), "%%rid%%");
var text url = URLRoot() & "db/" & Dbid() & "?a=er&rid=" & $rid;
"<a class='Vibrant Primary SaveBeforeNavigating' data-replaceRid=true href='" & $url & "'>Start Audit</a>"

  Here is the formula I used on the Rich Text Button (Finish Audit):

var text RID = If([Record ID#] > 0, ToText([Record ID#]), "%%rid%%");
var text Edit =  URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&rid=" & $RID & "&apptoken=XXXX&_fid_8="&ToTimeOfDay(Now());
var text DisplayURLMissingRID = URLRoot() & "db/" & Dbid() & "?a=dr&rid="; 
var text URL = $Edit & "&rdr=" & URLEncode($DisplayURLMissingRID) & $RID;

"<a class=\"Vibrant Primary SaveBeforeNavigating\" width:310px; text-align: center;\" href='" & $URL  & "'>Finish Audit</a>"

  Any advise would be greatly appreciated.

Luis Inciarte

1 Reply

  • Hi Luis!

    This is because formulas are evaluated as they change, so Now() gets evaluated when the page is loaded rather than when the button is clicked, meaning if you leave the page open for 5 mins before clicking the button, the time being captured was 5 mins ago.

    There is a way to capture the time that the button was actually clicked, however you'd need to leverage a Date/Time field rather than a Time of Day field. To do this you'd simply want to set the value of _fid_8=now where now is a text string rather than the function. That way, when the request is made you're telling the server to use the current time rather than the time that the page was loaded.

    So within your finish button logic go ahead and change this &_fid_8="&ToTimeOfDay(Now()) to this &_fid_8=now"

    Ryan Pflederer