Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1 through 15 (of 3,128 total)
  • Author
    Search Results
  • #54548

    In reply to: Conditional formatting

    Brendan
    Keymaster

    Yes, you can do that already. When you select a Date field on the Conditional Rule editor, you’ll see a popup that lets you select some options for the comparison. Is today is one of the options.

    Right now I just have AI used to generate forms for you based on a form name and description.

    I did play around with trying to get an LLM to do some generic queries based on data in the database, but it didn’t work that well. LLMs don’t seem to handle structured data very well. It’s great for summarizing large blocks of text and pulling out bits of data. But I was trying to ask it questions like “What’s the largest expense paid in the Electronics category?” It failed when using the local LLMs built-in to Apples OSs. And when I tried to get an external LLM to do it, I ended up going over the token limit because it would have to send the entire form’s data to the LLM service and then process the data there. It was just too much data to send.

    I did add a few new shortcuts to Tap Forms Pro 1.4 recently so you could ask it some pointed questions without scripting. Such as Find Records By Field Value and Find Most Common Value in Form in Field, etc.

    #54542
    Brendan
    Keymaster

    Hi Melanie,

    If you could please email me a sample form and script that demonstrates this crash that would really help me to figure it out. Send it to support@tapforms.com

    Thanks,

    Brendan

    #54539
    Brendan
    Keymaster

    Hi Gattopardi,

    I’ll look into that. For now though you could simulate that with a Calculation field or a Script field which returns whatever value you want to distinguish 0’s from nil values. Then just set the Group Records By option to that field.

    But it probably made more sense to me at the time to group nils and 0’s together with the Group Records by function. But I can see how you would want them separate.

    Thanks,

    Brendan

    Gattopardi
    Participant

    Hi Brendan,

    I’ve noticed what seems to be a grouping issue with Number fields in Tap Forms Pro.

    If a Number field contains a value and I delete that value, the field correctly appears empty. However, when I use this field with Group Records By, the record is placed in the 0 group, as if the empty field actually contained the value 0.

    I checked the value with a script:

    var value = record.getFieldValue(‘fld-0de…….’);

    if (value === undefined) {
    return “UNDEFINED — no value”;
    }

    return “VALUE: ” + value;
    For the affected record, the script returns:

    UNDEFINED — no value

    So the Number field really is empty and does not contain 0. It seems that Group Records By is treating undefined and the numeric value 0 as the same grouping value.

    Would it be possible for empty Number fields to remain in a separate empty group, rather than being grouped together with records whose value is actually 0?

    Thanks!

    #54532
    Melanie Schaaf
    Participant

    Hi Daniel,

    Thanks so much for taking the time to look into this and reply; I really appreciate that!

    Your diagnosis lines up with what I found through my own trial and error: I’d isolated the crash to the same spot, a loop combined with a second, differently-shaped Prompter (the null/’label’ confirm dialog alongside the popup one). Good to have that independently confirmed, this makes me more confident it’s a real bug worth Brendan’s attention rather than something odd in my own setup.

    Your scriptHandler/prompterHelper tool looks interesting! Thank you for providing this! I may well come back to it if I want the smoother “pick several at once” experience down the line. For now though, I’ve got a single-shot-per-click version running that avoids the crash entirely, but I might get tired of the extra clicking every time I want to link an additional record. So I’ll definitely keep your library in mind.

    Thanks again for chiming in. Also hoping you or Brendan might actually be able to isolate that underlying bug in future, but this was a great start.

    Best,
    Melanie

    #54531
    Daniel Leu
    Participant

    The issue is in promptConfirm, but I haven’t isolated it yet. I think it’s related to ‘null’ and ‘label’.

    I have a prompter library that implements this function as well. Due to a lack of time, I just used this with your code. You need to install my scriptHandler from https://lab.danielleu.com/tapformspro/script-library/scripthandler.html. This will install the prompterHelper as well which is used by the script.

    document.getFormNamed("scriptHandler").runScriptNamed("prompterHelper");
    
    async function Pick_Subtheme() {
        await pickSubtheme();
    }
    
    async function pickSubtheme() {
        var subthemes = [
            "Episode IV – A New Hope",
            "Episode VI – Return of the Jedi",
            "Classic Star Wars",
            "Lego Star Wars – Ultimate Collector's Series"
        ];
    
        var selected = [];
        var keepAdding = true;
        while (keepAdding) {
            try {
                await picklistPrompter("Pick Subtheme", "Add a Subtheme:", subthemes, subthemes[0]);
            } catch (err) {
                console.log("Cancelled: " + err, "#ff0000");
                break;
            }
    
            var chosen = prompterVar;
            selected.push(chosen);
            console.log("Selected: " + chosen);
            // … link the chosen record …
    
            var again = await yesnoPrompter("Add another Subtheme?", "Add Subtheme", "Done");
            keepAdding = (again === "Add Subtheme");
        }
    
        if (selected.length === 0) {
            console.log("No subthemes selected.");
        } else {
            console.log("Subthemes selected (" + selected.length + "): " + selected.join(", "));
        }
    }
    
    Pick_Subtheme();
    

    Cheers, Daniel

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

    Melanie Schaaf
    Participant

    Hi Brandon,
    hi all,

    I have been experimenting with a script in the last couple of days and ended up with a reproducible crash of Tap Forms with one version of it, that I thought that someone might want to look into. (Disclaimer: AI helped me write the script as my capabilities in JavaScript are beginner level at best).

    What I was doing: I have a script button on a custom layout that lets me pick an existing record from another form and link it via record.addRecordToField(), using Prompter.new() with a ‘popup’ parameter to show the choices. To add several linked records in one go, we wrapped that in a while loop and added a second Prompter (a simple Yes/No confirm using addParameter(message, null, “label”)) asking “add another?” after each pick.

    The bug: As soon as this script has two different Prompter-based functions in it — even though the second one (the confirm) is never actually reached — the very first prompt crashes the whole app the moment I click its Continue button. It’s 100% reproducible, happens both from the live layout button and from the script editor’s own Run button, and happens regardless of which item I pick in the dropdown (including leaving it on the default first item).

    If I strip the script down to a single Prompter call with no loop and no second Prompter function anywhere in the script, it works perfectly every time.

    Here’s the full script that causes the crash:

    async function Pick_Subtheme() {
    await pickSubtheme();
    }

    async function pickSubtheme() {
    var keepAdding = true;
    while (keepAdding) {
    var chosen = await promptPopup(“Add a Subtheme:”, “Pick Subtheme”, [“Episode IV – A New Hope”, “Episode VI – Return of the Jedi”, “Classic Star Wars”, “Lego Star Wars – Ultimate Collector’s Series”]);
    if (!chosen) { keepAdding = false; break; }
    // … link the chosen record …
    keepAdding = await promptConfirm(“Add another Subtheme?”, “Add Subtheme”, “Done”);
    }
    }

    function promptPopup(message, popupName, valuesArray) {
    return new Promise(function (resolve) {
    choice = undefined;
    var p = Prompter.new();
    p.addParameter(message, “choice”, “popup”, valuesArray, valuesArray[0]);
    p.cancelButtonTitle = “Cancel”;
    p.continueButtonTitle = “Add”;
    p.show(popupName, function (status) {
    resolve(status === true ? choice : false);
    });
    });
    }

    function promptConfirm(message, continueTitle, cancelTitle) {
    return new Promise(function (resolve) {
    var p = Prompter.new();
    p.addParameter(message, null, “label”);
    p.cancelButtonTitle = cancelTitle;
    p.continueButtonTitle = continueTitle;
    p.show(message, function (status) {
    resolve(status === true);
    });
    });
    }

    var choice;
    Pick_Subtheme();

    The crash happens the moment I click “Add” on the very first popup — execution never even reaches promptConfirm.

    Crash log (Thread 0, the crashed thread):

    Exception Type: EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Exception Reason: *** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]

    Termination Reason: Namespace SIGNAL, Code 6, Abort trap: 6
    Terminating Process: Tap Forms Pro [31720]

    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

    10 CoreFoundation -[__NSArrayM objectAtIndex:] + 592
    11 Tap Forms Pro 0x104f1a564 0x104dd0000 + 1353060
    12 CoreFoundation __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148

    I am using Tap Forms Pro 1.3.1 (Build 560) with macOS Tahoe 26.6.2.

    I’m happy to send the full crash report if useful. Thanks for looking into it!

    Melanie

    #54529
    Daniel Leu
    Participant

    This is the skeleton for your document script.

    function clearImportFlag(form) {
        const import_id = form.getFieldNamed('Import').getId();
        let changed = 0;
    
        // put your record loop here
        ....
    
        return changed;
    }
    
    for (const thisForm of document.fetchForms()) {
        let changed = 0;
        console.log("Clearing flags for form " + thisForm.name);
        changed = clearImportFlag(thisForm);
        console.log('Records changed: ' + changed);
    }
    
    document.saveAllChanges();
    

    Note, I didn’t try to run the script….

    Cheers, Daniel

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

    #54527
    Victor Warner
    Participant

    In my Document there are a number of Forms, each of which has a field (all called “Import”). For some records in the Import field in each Form there is a letter “X”.

    This setup distinguishes records imported from another database. After some work on the imported records, I wish to delete the content of the fields which contain the “X” (not the record itself).

    The (Form) script I have to do this is below (one for each Form).

    However, I have to go into each Form and run the script.

    Is there a way:

    1. to run all the scripts at once (one after another)?, or
    2. to have a (Document) script which can go into each Form and delete the X in the Import field.

    The script:

    var importFieldID = 'fld-6514c959cf9d4b169d3696a6ba49a56b';
    [Changed for each Form]
    
    // Get all records in this Form
    var records = form.fetchRecords();
    
    var changed = 0;
    
    for (var i = 0; i < records.length; i++) {
    
        var rec = records;
    
        // Get the value of the Import field
        var value = rec.getFieldValue(importFieldID);
    
        // Only clear records where Import is exactly X
        if (value == 'X') {
            rec.setFieldValue(importFieldID, '');
            changed++;
        }
    }
    
    // Save the changes
    document.saveAllChanges();
    
    console.log('Records changed: ' + changed);
    

    Any help would be gratefully received.

    #54525
    Daniel Leu
    Participant

    Yes, you can use buttons to launch scripts using custom layout or universal layout. You can navigate to a child record as well and back.

    This is how my own navigation menu for my CRM form looks like. So many things can be done.

    Attachments:
    You must be logged in to view attached files.

    Cheers, Daniel

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

    #54523
    Melanie Schaaf
    Participant

    Hello there,

    I have recently switched from Tap Forms 5 to Tap Forms Pro.

    While everything looks promising so far, there is an issue that I have not been able to solve.

    I usually make my own Layouts in Tap Forms 5 and like to customize everything so it is not only visually pleasing but also easy to navigate.

    Coming from Tap Forms 5 I always hated the look of linked forms in custom layouts. They are bulky, barely customizable in shape and color and jump out of the surrounding layout in a way that I find distracting.

    In Tap Forms 5 I usually use a workaround:

    I set the dimensions of the linked forms table very small, so that only the controls at the bottom of the field are visible. That lets me pick records to link or access them, but I don’t have to see the big white table in my parent layout. To display linked records in any parent form, I use a script that concatenates and displays values from the linked records. See screenshot for what that looked like in Tap Forms 5 you have the small linked form tables shrunk only to display the controls on the right and the values of linked records on the left.

    In Tap Forms Pro, table fields of linked forms don’t really disappear anymore, when you make them really small, but part of the table always remains visible. Also, they seem to forget that you switched off their background color, so every time you re-open Tap Forms, they will appear with thick white frame in addition to the table portion that can not be hidden or changed in color (see second screenshot). It is annoying.

    I have been wondering if there is a different workaround from the one I have been using, possibly by using scripting. I am just not that experienced in using Java Script. Is it even possible to embed a button in a form that lets you run a script and have that script take you to the linked records in that linked form?

    Any help or ideas will be greatly appreciated!

    Melanie

    Attachments:
    You must be logged in to view attached files.
    #54512
    Brendan
    Keymaster

    No, Tap Forms will only run a calculation or script for the currently viewed record when you make a change to a field that’s referenced by a calculation or script field.

    Why it’s taking 2 – 4 seconds before it allows you to make another change is a mystery.

    If you’d like me to do a performance evaluation on your document, you can send a backup file to support@tapforms.com and I’ll take a look at it.

    #54511
    Detlev Ott
    Participant

    No, there are no calculations, scripts or any other type of logic behind. The database document contains roughly 20.000 records but most of the forms are just a collection of text fields. The whole document is for reference only – without any calculation or other high performance demanding stuff.

    1 form with 500 records contains icons but this form has no relation to the form that was updated. There are only 2 forms that are linked (n:m) but they are not effected by the changes.

    Does every change in one form lead to recalculation in all other forms of the same document? If so perhaps the number of records causes the issue.

    #54510
    Brendan
    Keymaster

    Oh that’s very strange. I’ve never seen that or heard of that issue before. Do you have any Calculation or Script fields that may be running when a value in your field is changed? That could definitely be causing some performance issues depending on the formula or script.

    Chris Medeiros
    Participant

    Hi Brendan,

    The field in question is called Ending Mileage.

    I tried your suggestion and duplicated a record. After the sync, all the fields had there values transferred from the duplicated record.

    If I go back and make a small change to the Ending Mileage field in Mac OS, the change will occur on some records on my iOS device. If I make a small change on the iOS side, no records receive the updated change on the Mac OS side for that field.

    The issue with the Ending Mileage field seems to happen only when the record is created with the script I run. If I enter a new record manually, the issue doesn’t occur. All fields transfer correctly and I can make small changes that sync properly.

    The script creates a new record, taking the ending mileage from the previous record and placing it in the new record’s beginning mileage field. I then, manually, add the ending mileage into the new record. It’s that Ending Mileage value I enter that is not syncing.

    1 var beginning_mileage_id = ‘fld-dac67386ca7d4603b26f76b16554f162’;
    2 var ending_mileage_id = ‘fld-adb786f0ef994f84bf565d422f6537b0’;
    3
    4 var ending_mileage = record.getFieldValue(ending_mileage_id);
    5
    6 var newRecord = form.addNewRecord();
    7 newRecord.setFieldValue(beginning_mileage_id, ending_mileage);
    8
    9 console.log(ending_mileage);
    10
    11 form.saveAllChanges();

Viewing 15 results - 1 through 15 (of 3,128 total)