How to assign current date in script

Tagged: 

Viewing 2 reply threads
  • Author
    Posts
  • October 16, 2018 at 6:11 PM #31065

    Daniel Leu
    Participant

    Hi Brendan,

    I try to assign the current date to a field using a script.

    First try:

    theRec.setFieldValue(date_sold_id, Date());

    Doesn’t show anything. If I change date_sold to a text field it works. Then I tried to get the date number:


    theRec.setFieldValue(date_sold_id, Date.parse(Date()));

    Doesn’t work either. But something like this works:


    theRec.setFieldValue(date_sold_id, theRec.getFieldValue(date_modified_id));

    When using a script, how can I assign the current date to a field? Thanks!

    — Daniel

    October 17, 2018 at 1:37 AM #31070

    Brendan
    Keymaster

    Hi Daniel,

    The problem with the Date() function is it’s returning the date as a String. And you’re trying to set that on a Date field.

    So what you need to do is use:

    var currentDate = new Date();

    I just tested it and it works. Internally the new Date() function will convert to an NSDate which is what Tap Forms needs for setting on the field.

    Thanks!

    Brendan

    October 17, 2018 at 9:44 AM #31075

    Daniel Leu
    Participant

    Hi Brendan,

    Perfect, this works for me too! Thank you for your help.

    — Daniel

Viewing 2 reply threads

You must be logged in to reply to this topic.