Discussions

 View Only
  • 1.  Refresh Current Time before Creating or Editing Records

    Posted 07-13-2016 00:07

    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!



  • 2.  RE: Refresh Current Time before Creating or Editing Records

    Posted 07-13-2016 11:19
    This will require JavaScript to capture the time.  You will likely need to contract with a developer to get to the solution you want.


  • 3.  RE: Refresh Current Time before Creating or Editing Records

    Posted 07-22-2016 14:51
    This is easy to do. Post your complete formula.


  • 4.  RE: Refresh Current Time before Creating or Editing Records

    Posted 09-30-2016 14:37
    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>


  • 5.  RE: Refresh Current Time before Creating or Editing Records

    Posted 07-05-2017 11:21
    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


  • 6.  RE: Refresh Current Time before Creating or Editing Records

    Posted 07-11-2017 13:07
    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


  • 7.  RE: Refresh Current Time before Creating or Editing Records

    Posted 09-30-2016 19:43
    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>"


  • 8.  RE: Refresh Current Time before Creating or Editing Records

    Posted 05-24-2017 15:26
    Thanks, Nathan.

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

    Gaurav


  • 9.  RE: Refresh Current Time before Creating or Editing Records

    Posted 09-30-2016 19:46
    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!


  • 10.  RE: Refresh Current Time before Creating or Editing Records

    Posted 09-30-2016 19:53
    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.