Discussions

 View Only
Expand all | Collapse all

Time In/Time Out Formula

  • 1.  Time In/Time Out Formula

    Posted 05-16-2022 19:19
    Hello, can someone help me with the formula for getting the current date/time and set it as value on field with a click of a button? Basically, I'm trying to create a time in/out table where it will have two buttons and two fields. Clicking the Time In button populates the Time Int field with the current date/time, same thing for the Time Out button.

    ------------------------------
    frnmj
    ------------------------------


  • 2.  RE: Time In/Time Out Formula

    Posted 05-16-2022 19:25
    not tested but try thisas a formula URL button

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord"
    & "&apptoken=xxxxxxxxx" // if you have app tokens enabled
    & "&_fid_99=now";  /// assumes the field ID 99 is the date time field to be updated.

    var text RefreshPage = URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();


    $URL
    & "&rdr=" & URLEncode($RefreshPage)

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------



  • 3.  RE: Time In/Time Out Formula

    Posted 05-16-2022 19:33
    Edited by frnmj 05-16-2022 19:52

    Thank you so much for the quick reply, I tried it out but I could not save the formula due to an error. It says it's Expecting datetime but found text.



    ------------------------------
    frnmj
    ------------------------------



  • 4.  RE: Time In/Time Out Formula

    Posted 05-16-2022 19:52

    I changed the field type from "Formula - Date/Time" to "Formula - Text" and the error went away. However, when I tried it out it takes me to this page:



    ------------------------------
    frnmj
    ------------------------------



  • 5.  RE: Time In/Time Out Formula

    Posted 05-16-2022 20:24
    The field type for the button to push is formula URL.  You need to adjust the 99 to be the field ID of the date time field you want to update.

    I suggest that you disable the need for application tokens.  That is set in the App Properties.

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------



  • 6.  RE: Time In/Time Out Formula

    Posted 05-16-2022 21:45

    I have now changed the field type to "Formula - URL" and disabled application tokens. However, when I click on the button, it takes me to this page: 



    ------------------------------
    frnmj
    ------------------------------



  • 7.  RE: Time In/Time Out Formula

    Posted 05-16-2022 21:48
    Please post your code for the button

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------



  • 8.  RE: Time In/Time Out Formula

    Posted 05-16-2022 21:50
    Actually,   I see I was missing the record ID parameter, please adjust this part of the code.

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord"
    & "&rid=" & [Record ID#]
    & "&_fid_99=now";  /// assumes the field ID 99 is the date time field to be updated.

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------



  • 9.  RE: Time In/Time Out Formula

    Posted 05-16-2022 22:14
    Edited by frnmj 05-16-2022 22:25
    Thank you so much! It's working now. Right now, it's working in Edit/View so I'll use this one for the Time Out Button.



    Is there a way to make it work in "Add" so I can use it for Time In as well? For now, I'm using a Dynamic Form Rule to set the field value of Time In field to the current date/time after the record is saved. 

    ------------------------------
    frnmj
    ------------------------------



  • 10.  RE: Time In/Time Out Formula

    Posted 05-17-2022 09:41
    The formula for that is more complicated and the field type need to be formula rich text.

    var text RID = IF([Record ID#] > 0, ToText([Record ID%]), "%%rid%%)";

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord"
    & "&rid=" &  $RID
    & "&_fid_99=now"; 

    "<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #4b7097; border-radius: 5px; color: #ffffff; display: inline-block; padding: 0px 0px 0px 0px; width:100px; text-align: center; text-shadow: none; border: 2px solid #030404; font-size: 12px \"href='"
    & $URL
    & "'>Clock In</a>"


    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------



  • 11.  RE: Time In/Time Out Formula

    Posted 05-17-2022 14:01
    Edited by frnmj 05-17-2022 14:30

    I really appreciate your help. I applied your formula and made sure to change the fid to the correct one but I get an error. Here's a screenshot:

    Also, I think there's a typo in the first line:

    var text RID = IF([Record ID#] > 0, ToText([Record ID%]), "%%rid%%)";

    I changed it to this:

    var text RID = If([Record ID#] > 0, ToText([Record ID#]), "%%rid%%)");

    EDIT

    I found an extra parenthesis in the first line and removed it, here's the updated one:

    var text RID = If([Record ID#] > 0, ToText([Record ID#]), "%%rid%%");

    The error message has now changed to:
    <errdetail>Missing "rid" parameter.</errdetail>



    ------------------------------
    frnmj
    ------------------------------



  • 12.  RE: Time In/Time Out Formula