Read Records from a not linked Form in Tap Forms Pro

Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch Forums Script Talk Read Records from a not linked Form in Tap Forms Pro

Viewing 6 reply threads
  • Author
    Posts
  • February 8, 2026 at 1:38 PM #53540

    Steve-Kai Vyska
    Participant

    Hello everyone,

    sorry I’m giving up. What I’m trying to do is simple. I have a form, wich is not linked, and I want to get the records to do searches in it.

    According to everything I found this is done Very easy:

    var copyRecords = document.getFormNames(‘form1’).getRecords();

    when I try this, get an Error

    TypeError: copyDummy.getRecords is not a function. (In 'copyDummy.getRecords()', 'copyDummy.getRecords' is undefined), line:(null)

    my next try was to separate it:
    var copyForm = document.getFormNamed(‘form1’);
    var copyRecords = copyForm.getRecords();
    same Error

    going through the javascript doku on the support page I found

    var copyRecords = document.getFormWithId(form1_id);

    but I can not find a possibility to loop the records.

    I think I’m thinking something wrong here but I do not get what.

    Thanks for all hints

    February 8, 2026 at 9:30 PM #53541

    Brendan
    Keymaster

    var copyRecords = document.getFormNamed('Form 1').fetchRecords();

    Check the API docs for Tap Forms Pro:

    https://www.tapforms.com/help-mac/pro/en/topic/javascript-api

    February 13, 2026 at 2:24 PM #53552

    Steve-Kai Vyska
    Participant

    Hello

    I Still do not get it.

    I got it to work to fetch Records and use a Look to cycle through it

    var formID = 'frm-e1192cd5b1724314b84fa584a02cca51';
    var fieldID = 'fld-4c4ca5ba0da744e385e552ab5601fee0';
    
    var myCopyForm = document.getFormWithId(formID);
    var myReordsCopyForm = myCopyForm.fetchRecords();

    now I can go loop the Records, that is ok

    In the API is described a Function fetchRecordsForSearchTerm() which returns an array with the Records including a “search Term”

    so my Idea was to use:

    var mySearchedFormRecords = myCopyForm.fetchRecordsForSearchTerm("2025", fieldID);

    in the Records the field (wich is a textfield) contains some Records with “2025” and some with “2026” but when I try to loop through the mySearchFormRecords I get a 0 as length.

    What am I doing wrong?

    Steve

    February 13, 2026 at 2:53 PM #53555

    Steve-Kai Vyska
    Participant

    I’m not sure but after a reload of the Database everything works now….

    February 15, 2026 at 5:41 AM #53557

    Steve-Kai Vyska
    Participant

    Hi everyone,

    Sorry to follow up again here,

    I’m trying to load a dataset that I retrieve using fetchRecordsForSearchTerm('2026', feldJahrID). Unfortunately, there doesn’t seem to be any filtering happening at all. No matter what I enter as the search string, I almost always get nearly all records back.

    If I search for “1”, I get 4 records. With “12” or “123”, I get 2 records. If I use “2”, I also get 4 records. Searching for “202” returns 4 records, and with “203” I get 3 records.

    Either I completely misunderstand how the function works—in which case I apologize, because then, as usual, the problem is sitting between the keyboard and the chair—or something is definitely not working correctly here.

    Thanks in advance for any information.

    Steve

    I’ll put the Script here because the Database has 12 MB so I can not upload ist

    function Erstelle_Aktuellen_Monat() {
    
        // Aktuelles Datum ermitteln
            var aktuellesDatum = new Date();
            var aktuellesDatumTag = aktuellesDatum.getDate();
            var aktuellesDatumMonat = aktuellesDatum.getMonth() + 1;
            var aktuellesDatumJahr = aktuellesDatum.getFullYear().toString();
    
        // Formular Monatsübersicht mit benötigten Feldern
            const formularMonatsuebersichtID = 'frm-e1192cd5b1724314b84fa584a02cca51';
            const feldJahrID = 'fld-4c4ca5ba0da744e385e552ab5601fee0';
            const feldMonatID = 'fld-9ccdf4162fed4721adaea441d9ff2d43';
            const feldzugehörigeHausidID = 'fld-6841ad10151b477c86de0396fd186d75';
    
        // Unterformular Zahlungseingänge mit benötigten Feldern
            const formularZahlungseingaenge_id = 'fld-6fc140552dbc4a32a1dc078f7268d6e0';
            const feldMieter_id = 'fld-ca6166213bf94662a7a7e04eff78b0d5';
            const feldWohnung_id = 'fld-330fd8f304094d64bb99ddbfa4f9af8b';
            const feldErwartete_einzahlung_id = 'fld-5f60efaf3c6043f2b008a65de6fd47c6';
    
        // Formular Mietvertrag
            const formularMietvertrag = 'frm-556cccd18f174e20982227e870784b87';
            const feldMietvertragMieterID = 'fld-f9505864e6c048079fee1f640d13ba23';                               // formatierter Name des Mieters
            const feldMievertragWohnungID = 'fld-6779828c393c46dfb1e6d547b4c75f8d';                               // Formatierte Whung (Haus + Wohnungsnummer)
            const feldMietvertragDatumBeginnDesMietverhältnissesID = 'fld-7a5d9c2d2dd140fd85ebb7c4e7996fff';      // Ab wann gilt der Mievertrag
            const feldMietvertragDatumEndeDesMietverhältnissesID = 'fld-af2bf0064540430d8c070d138a9a3ba3';        // Gilt dieser Vertrag noch
            const feldMietvertragWarmmieteID = 'fld-1562739d1b1144c7ad250a0e7b379080';                            // Das müsste auf dem Kontoauszug erscheinen
            const feldMietvertragNebenkonstenSummeID = 'fld-3e8a8d04ce1944fb8eac5db9ede21391';                    // Nebenkosten die mit gezahlt wurden (zur Gewinn berechnung benötigt)
    
        // Weitere Variablen zum verarbeiten
            var datensatzErstellt = 0;
    
        // Monatsübersicht öffnen
        console.log("Hole das Formular Monatsübersicht");
            var formularMonatsuebersicht = document.getFormWithId(formularMonatsuebersichtID);
    
        // Alle Datensätze holen, welche dem aktuellen Jahr entsprechen
            console.log("Lese die Datensätze, für das Jahr: " + aktuellesDatumJahr);
            var auswahlRecoredsMonatsuersicht = formularMonatsuebersicht.fetchRecordsForSearchTerm('2026', feldJahrID);
    
        // Kontrollieren ob es Datensätze gibt
            console.log("Kontrollieren ob es Datensätze gibt");
            if (auswahlRecoredsMonatsuersicht.length == 0) {
                // Es liegen keine Datensätze für das Jahr vor
                    console.log(auswahlRecoredsMonatsuersicht.length + " Datensätze gefunden");
    
                // Da keine Datensätze für das Jahr vorliegen, kann für das aktuelle Haus ein Datensatz ertellt werden
            } else {
                // Es liegen Datensätze für das Jahr vor
                    console.log(auswahlRecoredsMonatsuersicht.length + " Datensätze gefunden");
    
                  // jetzt kontrollieren, ob diese auch für das aktuelle Haus sind
                    console.log("Kontrollieren ob einer für das ausgewählte Haus ist");
                        for (var index = 0, count = auswahlRecoredsMonatsuersicht.length; index < count; index++){
                    		if (auswahlRecoredsMonatsuersicht[index].getFieldValue(feldzugehörigeHausidID) == record.getFieldValue(feldzugehörigeHausidID)) {
                                // Für das Haus gibt es bereits einträge
                                console.log("Einen Eintrag gefunden: " + auswahlRecoredsMonatsuersicht[index].getFieldValue(feldJahrID));
                                datensatzErstellt = 0;
                            } else {
                                // Für das Haus geibt es keine Einträge
                                console.log("Haus nicht gefunden");
    
                                // Neuen Datensatz erstellenb
                                datensatzErstellt = 1;
                            }
                    	}
            }
    //    document.saveAllChangesAndRefresh();
    }
    February 15, 2026 at 8:09 PM #53559

    Daniel Leu
    Participant

    You could try with following code snippet. Just add this at the beginning of your script. It adds the fetchRecordsWithMatch() function to the form object and presumably does a similar (or better?) thing than fetchRecordsForSearchTerm():

    // form.fetchRecordsWithMatch
    // Returns all records where the specified field matches the given value.
    CDForm.prototype.fetchRecordsWithMatch = function(field_id, value){
        return this.fetchRecords().filter(x => x.getFieldValue(field_id) == value);
    }
    

    And then instead of var auswahlRecoredsMonatsuersicht = formularMonatsuebersicht.fetchRecordsForSearchTerm('2026', feldJahrID); use var auswahlRecoredsMonatsuersicht = formularMonatsuebersicht.fetchRecordsWithMatch(feldJahrID, '2026');

    This will return a record where all records are an extract match. This is what I have in my TF API Extensions script.

    Viel Spass!

    • This reply was modified 1 day, 2 hours ago by Daniel Leu.

    Cheers, Daniel

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

    February 16, 2026 at 3:21 AM #53568

    Steve-Kai Vyska
    Participant

    Grüezi,

    Thanks for the code snippet, I’ll try it out later, including your ScriptHandler. By the way, while we’re on the topic of scripts, there might be a translation error in the German version. In the script overview, there’s a section with the little gear icon… it says “move to document,” but there is no “document” in the German overview. I think it should say “favorites,” and under “favorites” it should then say “switch to Formular.” I think the translation isn’t quite correct here.

    Nice Week

    Steve

Viewing 6 reply threads

You must be logged in to reply to this topic.