Can I use Functions from Calculation Field in Scripts, e.g. DATEADD

Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch Forums Script Talk Can I use Functions from Calculation Field in Scripts, e.g. DATEADD

Viewing 3 reply threads
  • Author
    Posts
  • May 7, 2025 at 12:14 PM #52127

    Harry
    Participant

    I have a form in Tap Forms Pro that calculates subscription renewal dates to keep track of all my subscriptions. It uses several calculation fields that use Date and Time functions to determine the renewal date. I would like to create a script to consolidate all the calculations into one script field.

    Using a post here from May 2, 2020, “how to use dateadd in a script”, I tried this as a test, but got an error that said Test: ReferenceError: Can’t find variable: dateadd, line:(null).

    function Test() {
    
        var start_date = record.getFieldValue('fld-037157d2f1fa4a75959f3a6c0128a8c1');
        var renew_date = dateadd(start_date,1,0,0,0,0,0,0);
        return renew_date;
    
    }
    
    Test();

    Is it possible to use the these functions from calculation fields such as TODAY, NOW, DATEADD, YEARS, MONTHS, and DAYS in a script?

    Thanks,
    Harry

    May 7, 2025 at 4:00 PM #52128

    Daniel Leu
    Participant

    You have to use the Javascript equivalent. There’s a bunch of functions available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date.

    dateadd() is not a Javascript function and can’t be used. If you continue to go through the thread you found, you’ll see how to add an hour to your current date/time. Here’s the link to the thread for everyone else following: https://www.tapforms.com/forums/topic/how-to-use-dateadd-in-a-script/#post-40449

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    May 7, 2025 at 4:36 PM #52129

    Harry
    Participant

    Thanks so much. Exactly what I was looking for. Now to translate all my algorithms using JavaScript functions.

    May 19, 2025 at 10:09 AM #52282

    Harry
    Participant

    Just to follow up. I translated 4 calculation fields with long complex formulas to a single script field using JavaScript and deleted these 4 calculation fields. Thanks again to Daniel Leu for pointing me in the right direction.

    May 19, 2025 at 1:18 PM #52286

    Daniel Leu
    Participant

    Thank you for letting me know that it worked for you!

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

Viewing 3 reply threads

You must be logged in to reply to this topic.