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,131 total)
  • Author
    Search Results
  • #54598
    Marcel Halbeisen
    Participant

    So, I also try to use the data base now on my MacBook, but it totally failed. It’s absolutely not possible to sync the complete datas from the Cloud+ Sync to the MacBook. Only around 40% of the entries come to the MacBook.
    I also tried to open the backup from the iPhone on the MacBook, which works, but It’s then not possible to use the Cloud+ Sync because the file has the same name and then it’s not possible to use it. And if I gave him another name, I have then two databases, and only the one with less datas get’s synchronized.
    Completely unusable :-(

    Finally I have to say, that it seems to be impossible to use Cloud+ Sync on a save way with Tap Forms. The alternative for me, which is not what I want, is to use Tap Forms only on my iPhone and iPad. But then, I have also to stop my MacOS+iOS subscriptian and use only the iOS subscription. But I need my datas also on the MacBook, so which alternative do I have???

    #54597
    Tom Seputis
    Participant

    Hi Brendan,

    Thanks for the extremely quick response. The whole issue for this formula not working was the curly quotes. I was not aware of how subtle the difference is in the way that they look. Changed to straight quotes and now it all works fine.

    I will have to learn more about scripting if I try anything more complicated than this.

    Thanks Again,
    Tom

    #54596
    Brendan
    Keymaster

    It also starts to get really complicated to diagnose when you have so much nesting going on within the expression. That’s when I switch to a Script field instead of a Calculation field.

    #54572
    Brendan
    Keymaster

    So you’re using the new Conditional Visibility rules to decide to show or hide a field? I don’t think I tested the condition where the value is changed from within a script. I’ll have to look into that. I had just been focused on when you change values using the user interface.

    Also you should only need a single document.saveAllChangesAndRefresh() at the very end of your script, after you make any changes. So that record.refreshCalculations() should go before the save function call.

    #54570
    tekl mister
    Participant

    I’ve a simple form with two date fields (start and end) and some other fields. The first date field is populated with the current date. The second date field is empty. And some fields are hidden until the second field contains a date. To make it easier for the user, I’ve added a button to a Universal layout. When I click the button, the date field should be filled with the current date. I use this script for the task:

    function MyScript() {
        var field_id = 'fld-b64c54dfb3de446fbf2b25b203c90104';
        
        record.setFieldValue(field_id, new Date(), true);
        record.refreshCalculations();
        form.saveAllChanges();
        document.saveAllChangesAndRefresh();
        record.refreshCalculations();
        }
    
    MyScript();

    As you can see, I tried a lot to make the button work. But it doesn’t. After clicking, nothing happens. When I click on an empty area of the form, the second date field shos its content. But the hidden fields are still hidden, I’ve to switch layouts or record to let Tap Forms update the screen.

    Is there a way to refresh the view? Or did I something wrong?

    #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

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