How to run/code script to operate in multiple Forms

Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Script Talk › How to run/code script to operate in multiple Forms

Viewing 1 reply thread
  • Author
    Posts
  • September 15, 2026 at 7:08 AM #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.

    September 15, 2026 at 12:46 PM #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

Viewing 1 reply thread

You must be logged in to reply to this topic.