How do you set a Time field with a Script?

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Using Tap Forms How do you set a Time field with a Script?

Viewing 3 reply threads
  • Author
    Posts
  • March 31, 2019 at 1:58 PM #34148

    A Ibanez
    Participant

    I created a Time field (not datetime) and I want to set its value with a script.

    I have tried the following:

    
    inRecord.setFieldValue(broadcast_jst_id, "01:05");
    
    
    inRecord.setFieldValue(broadcast_jst_id, new Date("01:05"));
    

    Unfortunately after the script runs the field is blank.

    March 31, 2019 at 10:45 PM #34207

    Brendan
    Keymaster

    Did you call form.saveAllChanges() after you called record.setFieldValue() ?

    It does require a proper Date object, so the first example wouldn’t work.

    Also, new Date("01:05") is an invalid date.

    See this page for Date examples:

    https://www.w3schools.com/js/js_dates.asp

    April 1, 2019 at 8:25 AM #34210

    A Ibanez
    Participant

    Hi Brendan. Yes, I’m calling saveAllChanges(). All other fields get populated correctly, it’s just this one that doesn’t.

    I tried doing it like this:

    inRecord.setFieldValue(broadcast_jst_id, new Date(0,0,0,1,5,0));

    But Tapforms displays “00:32” for some weird reason. Note that this this just a time field (Not Datetime).

    I think I will have to specify dummy year, month, and days in order to make it work. Gonna test that now.

    EDIT: Specifying dummy year, month, day worked like a charm.

    inRecord.setFieldValue(broadcast_jst_id, new Date(2017,1,1,1,5,0));

    April 1, 2019 at 6:45 PM #34222

    Brendan
    Keymaster

    You should set the dummy date to be January 1, 1970. That’s the Unix Epoch date/time which is what Tap Forms uses when it populates a Time field.

    April 2, 2019 at 1:46 PM #34240

    A Ibanez
    Participant

    That’s a good idea. I’m gonna make that the dummy values. Thanks.

Viewing 3 reply threads

You must be logged in to reply to this topic.