Refresh Current Time before Creating or Editing Records

  • 1
  • 2
  • Question
  • Updated 2 years ago
  • Answered

I have a set of URL formulas that run in a Formula -Text field when a button is clicked.

I'm invoking 2 sets of URLs in an HREF from pre-defined variables as follows:

&$URLeditlast& "&rdr=" & URLEncode($URLnew)& 

The URLeditlast URL puts a stop time in on a current record, the URLnew creates a new record with a start time.  This is the basis of a time tracking system

The problem is if the user leaves the page sitting idle the time doesn't' refresh. 

For example, if I create my new time entry at 4:49pm and the leave the page sitting for 10 minutes then click the button to create a new entry, the times recorded is still 4:49pm, not 4:59pm.  

I know if the user refreshes the page before they click the button this would solve the problem, however I do not want the user to have to do this (i have over 100 users in this quickbase all day long and there would be risk of time errors if people forget to refresh).  I would like the QuickBase self-refresh when the button is clicked and then run the two URLs above to perform the actions with hopefully a refreshed time value

I've tried many things and cannot get this to work, i'm hoping someone has some ideas.  Thanks!

Photo of gmcroberts

gmcroberts

  • 180 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
  • 2
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
This will require JavaScript to capture the time.  You will likely need to contract with a developer to get to the solution you want.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,024 Points 20k badge 2x thumb
This is easy to do. Post your complete formula.
Photo of Nathan

Nathan

  • 60 Points
We had this issue as well and resolved it with an onmouseover.

var text base = URLRoot() & "db/" & Dbid();
var text rdr = "&rdr=" & URLEncode($base & "?a=dr&rid=" & [Record ID#]);
var text url = $base & "?a=API_EditRecord&rid=" & [Record ID#] & "&_fid_<TARGET FID>=";

var text jquery="$(\"#timeTarget\").attr(\"href\",\""&$url&"\"+ now.replace(\",\",\"\") + \""&$rdr&"\")";

"<a id='timeTarget' href ='void' class='Vibrant' onmouseover='"&"var now = new Date().toLocaleString();"&$jquery&" '>BUTTON NAME</a>"
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
Hi Nathan,

I have a field called Flag that captures that button has already clicked. It means if someone has already started their time then, it will give an alert says 'Please end your shift first'.

In above formula, how can I use if condition in which Ist part will capture time and second part will give an alert?

Thanks,
Gaurav
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
I want to show an alert if the shift has already started.

Here is my formula:

var text base = URLRoot() & "db/" & Dbid();
var text rdr = "&rdr=" & URLEncode($base & "?a=dr&rid=" & [Record ID#]);
var text url = $base & "?a=API_EditRecord&rid=" & [Record ID#] & "&_fid_478=1" & "&_fid_475=";
var text jquery="$(\"#timeTarget\").attr(\"href\",\""&$url&"\"+ now.replace(\",\",\"\") + \""&$rdr&"\")";
If([Workday Flag]=0,
"<a id='timeTarget' href ='void' class='Vibrant' onmouseover='"&"var now = new Date().toLocaleString();"&$jquery&" '>Start Work</a>",
"javascript:alert('Please end your workday first.')")

Thanks,
Gaurav
(Edited)
Photo of Nathan

Nathan

  • 60 Points
Here is a better one I think, it is fully self-contained, uses an interval to refresh automatically and provides an output, make a field with whatever name you want.

var text base = URLRoot() & "db/" & Dbid();
var text rdr = "&rdr=" & URLEncode($base & "?a=dr&rid=" & [Record ID#]);
var text url = $base & "?a=API_EditRecord&rid=" & [Record ID#] & "&_fid_15=";

"<div id='rdr' value='"& $rdr &"'/>" &
"<div id='url' value='"& $url&"'/>" &

var text timeScript = "setInterval(function(){var d=new Date(); var cDate = d.toLocaleString().replace(',',''); var eDate = encodeURI(cDate); $('#timeTarget').text('Time ('+cDate+')'); var t= $('#url').attr('value') + eDate + $('#rdr').attr('value'); $('#timeTarget').attr('href',t);},1000);";

var text script = "(function(){"&$timeScript&"})();";

"<img src=' '  onerror=\"javascript: "&$script&" \"></img>"&

"<a id='timeTarget' href ='void' class='Vibrant'>Time</a>"
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
Thanks, Nathan.

I was looking for the same solution and it works for me. 

Gaurav
Photo of gmcroberts

gmcroberts

  • 180 Points 100 badge 2x thumb
I tried your first version, works amazingly well and solves a problem i've been trying to solve for a long time.  This is awesome, thank you so much!
Photo of Nathan

Nathan

  • 60 Points
Anytime, I would recommend the second one just because I am always nervous a user will break it, they always find a way, with the second one using a interval, it updates no matter what.