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,089 total)
  • Author
    Search Results
  • #54214

    In reply to: ordinal day?

    Glen Forister
    Participant

    OMG, how did I miss using the script window instead of the calc. I’m sorry. Just haven’t had to edit a script in a while I guess.

    I changed the field type to SCRIPT.
    I bring up the SCRIPT window and it has an example starting script. I can delete it, but I can’t past into the winddow the script you supplied.
    If I try to type it, I’ll have many mistakes to weed out and that will be a big waste of both of our time.
    How can I paste something into that SCRIPT window. I remember not being able to add the fld- number by copy and paste, but I never complained about that until now.

    #54210

    In reply to: Using tablefields

    Daniel Leu
    Participant

    You can use field.sortedTableFields to get field details of a table.

    Following function copies the values from the source record to a new row in the table of the current record. I’ve verified for text and number fields.

    /**
     * copyRecordToTable(srcRecord, tableId)
     *
     * Copies values from srcRecord into a new row appended to the table field
     * identified by tableId, for all fields whose names match between the
     * source record's form and the table.
     *
     * @param {TFRecord} srcRecord  - The source record to copy values from.
     * @param {string}   tableId    - The field ID of a Table-type field on the record.
     * @returns {TFRecord}          - The newly created table row record.
     */
    function copyRecordToTable(srcRecord, tableId) {
        // Resolve the table field from the record's own form using the field ID.
        const table = form.getFieldWithId(tableId);
    
        // Get the fields defined on the table, keyed by name for fast lookup.
        const tableFields = table.sortedTableFields;
        const tableFieldsByName = {};
        for (var i = 0; i < tableFields.length; i++) {
            var tf = tableFields;
            tableFieldsByName[tf.name] = tf;
        }
    
        // Add a new row to the table.
        const newRow = record.addNewRecordToField(tableId);
    
        // Walk every field on the source record's form and copy matching values.
        const sourceFields = srcRecord.form.fetchFields();
        for (var j = 0; j < sourceFields.length; j++) {
            var sf = sourceFields[j];
            var match = tableFieldsByName[sf.name];
            if (match) {
                var value = srcRecord.getFieldValue(sf.getId());
                newRow.setFieldValue(match.getId(), value);
            }
        }
    
        return newRow;
    }
    

    To verfiy, I use this sample script which just adds a random record to the table.

    function selectSourceRecord(formName) {
    	// return a random record from the form formName
    
    	const records = document.getFormNamed(formName).fetchRecords();
    	const index = Math.floor(Math.random() * records.length);
    	return records[index];
    }
    
    function Copy_Record_To_Product_Table() {
    
    	// source form name	
    	const sourceFormName = "Products";
    
    	// select a random record from the source form
    	const sourceRecord = selectSourceRecord(sourceFormName);
    
    	// table field name
    	const tableFieldName = "Products";
    
    	// get the table field
        const tableId = form.getFieldNamed(tableFieldName).getId();
    
    	// copy the record to the table
    	copyRecordToTable(sourceRecord, tableId);
    
        document.saveAllChangesAndRefresh();
    }
    
    Copy_Record_To_Product_Table();
    

    Let me know if this works for you!

    • This reply was modified 9 hours, 17 minutes ago by Daniel Leu.
    • This reply was modified 9 hours, 15 minutes ago by Daniel Leu.
    • This reply was modified 9 hours, 14 minutes ago by Daniel Leu.

    Cheers, Daniel

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

    #54209

    Topic: Using tablefields

    in forum Script Talk
    Steve-Kai Vyska
    Participant

    Hello everyone,

    I’m currently experimenting with the “Table Fields”.

    When creating one, there is an option to select a form. If I choose an existing form, I can use the button **”Copy fields into table…”** to insert the fields title from the previously selected form into the table. This works perfectly. However, I’m a bit curious about the description text displayed there:

    > “Tap Forms will copy values from the selected records based on matching field titles.”

    Is this functionality only available through the form selection field, or is there a way to achieve the same thing via scripting?

    When I tried to do this with a script, I could only get it working by hard-coding the fieldsIDs beforehand. In other words, if I add a new field to the table, I have to manually add the corresponding field ID to the script.

    Is there any way to read the table column headers via javascript, so that the script could iterate through them and (since the names are identical) retrieve the corresponding values from the original form automatically by getFieldNamed(‘Name’)?

    Thanks for any ideas, and have a great weekend!

    Steve

    #54208

    In reply to: ordinal day?

    Brendan
    Keymaster

    That’s a script for a Script Field. It’s not a formula for the Calculation Field.

    You need to also call return result; at the end of the script.

    But you also need to pass in your field’s date.

    Here’s a more full example:

    function Day_Number() {
    
        const dayOfYear = myDate => {
            const year = myDate.getFullYear();
            const firstJan = new Date(year, 0, 1);
            const differenceInMillieSeconds = myDate - firstJan;
            return (differenceInMillieSeconds / (1000 * 60 * 60 * 24));
        };
        var date_id = 'fld-22b8461cd7e14fbc988ecd1b7b22a013';
        let my_field_date = record.getFieldValue(date_id);
    
        const result = dayOfYear(my_field_date);
        return result.toFixed(0);
    
    }
    
    Day_Number();

    You’ll need to replace the date_id (‘fld-22b8461cd7e14fbc988ecd1b7b22a013’) with your Date field’s Field ID.

    #54205
    Paul Cotton
    Participant

    Re 10 – scripts triggering on field change: this was user error and Brendan provided the solution via email.

    I was using getId rather then explicitly identifying the field in the script itself:

    mine that didn’t work correctly:

    var currval=record.getFieldValue(form.getFieldNamed(“Currency”).getId());

    Brendan’s solution that works great:

    var currval=record.getFieldValue(‘fld-6cc122549b004a09b0e21e8b4f76b313’);

    #54204

    In reply to: ordinal day?

    Brendan
    Keymaster

    Here’s a JavaScript function which will give you the day of the year:

    const dayOfYear = date => {
        const myDate = new Date(date);
        const year = myDate.getFullYear();
        const firstJan = new Date(year, 0, 1);
        const differenceInMillieSeconds = myDate - firstJan;
        return (differenceInMillieSeconds / (1000 * 60 * 60 * 24) + 1);
    };
    
    const result = dayOfYear("2019-2-01");

    For the time of day, you can call myDate.getHours(), myDate.getMinutes(), myDate.getSeconds()

    #54201

    In reply to: ordinal day?

    Glen Forister
    Participant

    I don’t remember what form I was using when I was given that instruction (I keep that now) in my notes (questions TapForms). It could have been a script.
    I don’t care how I do it, you can see what i’m trying to do which is given the input from “Date & Time” in the first col., I want a day of year + a decimal for the time of day (hours & minutes).

    This is so I can graph Date & Time against what happens on that event which is from a number from 1-6.

    Thanks for looking.

    #54199
    Paul Cotton
    Participant

    Re 9 and updating latest date, in creating an example from scratch I realised that “recalculate formulas and scripts for all records” from the active form in single col view (rather than multi-col view) does work. I had completely missed that button on single-col view for some reason.

    I had an exact copy of the ipad file I brought back, tried it with that and it worked fine so can scratch that one from the list.

    • This reply was modified 2 days, 8 hours ago by Paul Cotton.
    #54196

    In reply to: ordinal day?

    Brendan
    Keymaster

    Where did you get the info for the DAYOFYEAR() function? It is not a function I have in the formula editor.

    Have you tried JavaScript to generate that?

    Thanks,

    Brendan

    #54189
    Daniel Leu
    Participant

    In another application, I used a checkmark field along with a field script to do some action. So you could have the same, once you set a checkmark field, the field script is triggered and that would clear all other checkmark fields.
    Now with your main script, you can locate the two records in their respective forms that have the checkmark field set and populate your third form.

    Cheers, Daniel

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

    #54179
    Paul Cotton
    Participant

    Re 9), I see that the ipad element makes no difference. I edited the subform direct on ipad as I couldn’t create a new subform record from within the parent form.

    On macos, I just tried adding a record direct into the form that is used as a subform and that didn’t update when I viewed the parent form either.

    It didn’t update when I tried multi-column > “recalculate formulas and scripts for all records”.

    Some tests did update using the “recalculate formulas” in the parent form – but one time it didn’t.

    Sadly that method isn’t practical as it requires my knowing which records are out of sync.

    Re the forum post edit issue, I see that is just the result of the short editing time window.

    • This reply was modified 5 days, 7 hours ago by Paul Cotton.
    • This reply was modified 5 days, 7 hours ago by Paul Cotton.
    • This reply was modified 5 days, 7 hours ago by Paul Cotton.
    • This reply was modified 5 days, 7 hours ago by Paul Cotton.
    #54175
    Paul Cotton
    Participant

    I’m a recent convert to Tap Forms Pro for macos. I originally used Bento, then moved to Filemaker when they shut that down, and have spent years setting up systems for various things in that. I’ve been unhappy with Claris as a company for years now, but felt locked in with no hope of finding a workable solution to break away. TFP has provided me with a way to do just that.

    I am extremely happy with TFP, but I encountered some issues in setting things up – some feel like bugs, some are no doubt just new user error/ignorance.

    1) In layout mode, line doesn’t layer on top of other shapes, text or images

    2) cmd c + cmd v page elements screws up editing, example:
    add a few fields to layout
    add rectangle to layout
    layer list: clicking in list selects the correct elements in layout
    cmd c + cmd v to duplicate rectangle
    note that it doesn’t create a new layer for the duplicate
    selecting in the layer list is now out of sync with the elements in the layout
    going to form view removes the duplicate rectangle
    back to layout view and delete the original rectangle – an entry in layers remains
    go to form view and the duplicate rectangle is visible again

    3) after making a backup of a password protected file via file>backup, on re-opening, the show/hide forms list, display form/layout inspectors, and advanced search buttons are all disabled (can still use drop down menu for these functions)

    4) File size seems massive relative to data size. Importing relatively modest csv’s has ballooned the TPF file-size, eg I have a csv with 17,191 records, 3.7MB total, and each record is ~200 characters long. Importing that increased TFP file size by 72.5MB, even after doing a “rebuild search index”. This is an example record:

    “max 5-letter word”,””,””,””,”4 characters”,””,””,”email address”,”email address”,”max 60 character term”,”max 60 character term”,”date”,”USD”,”number”,”date”

    A different 1MB excel file increased TFP by 10MB. The filemaker database I used was 65MB, including more data than I imported. The two equivalent TFP files total ~250MB.

    5) Notes fields do strange things with their margins. When I type to the very right-side edge of the notes field, all of the text jumps to hard-left, removing the lefthand margin. I have to move my cursor close to the left-side edge of the notes field and drag left to move the text back right. Dragging cursor right near right-side edge also moves the text left.

    6) A calculation field using + for multiple number fields sums fields until it hits an empty field, then treats that sum so far as text and concatenates the sum so far with the fields after as if text. Is there any way to either have empty number fields treated as 0, or to bulk change all empty fields to 0?

    7) Sorting text fields interprets the whole number portion at the beginning of a field rather as characters eg 1word,2word,10word, rather than 1word, 10word, 2word – is there any way to stop this?

    8) In note fields set to plain text and a specific font/size, new text defaults to font family=no value, typeface=””, and size=0, rather than the font set in layout view. Also, it does still recognise and store changes of font/style made in sections of the text.

    9) I have a form with a subform. The subform has records with dates, the main form has a calculation field that shows the latest date from the subform. This works fine in macos. I used TFP on an iPad, entering data into the subform direct. On reload to mac, it didn’t update the latest date fields when viewing those records.

    10) I have a text field that uses a pick list and a script field that listens for changes to that text field. When I change the value, the script isn’t executed – it only executes when I click on the bottom-left “recalculate formulas” button. I looked at the Books Library template and the Sortable Title script field in that behaves the same way for me.

    #54172
    Brendan
    Keymaster

    Hi Steve,

    If you double-click on the record number, then that record becomes the selected record and can be referenced by using record in your script. But there’s no tracking from JavaScript of what child record is merely selected from the spreadsheet view on a Table or Link to Form field.

    What are you trying to accomplish?

    Thanks,

    Brendan

    #54171
    Steve-Kai Vyska
    Participant

    Hello everyone,
    I have a form that contains a subform. In this subform, you can select a specific row by clicking the number at the front, for example to delete it.

    Is there any way to get the ID of the selected record from the main form? Using a script or a script field would both be fine.

    Best regards,
    Steve

    #54143
    Daniel Leu
    Participant

    My script works with Tap Forms Pro. Here’s an example using my script showing just the EXIF data of an iPhone image:

    5/19/26, 11:19:12 AM / new form / First photo date
    {
        "WhiteBalance": 0,
        "PixelYDimension": 640,
        "LensMake": "Apple",
        "OffsetTimeOriginal": "-07:00",
        "MeteringMode": 3,
        "ColorSpace": 1,
        "LensModel": "iPhone 13 Pro back triple camera 5.7mm f/1.5",
        "DateTimeDigitized": "2026:05:16 20:00:32",
        "ExposureProgram": 2,
        "OffsetTimeDigitized": "-07:00",
        "ExifVersion": [
            2,
            3,
            2
        ],
        "SubsecTimeDigitized": "392",
        "ExposureBiasValue": 0,
        "ISOSpeedRatings": [
            100
        ],
        "LensSpecification": [
            1.5700000524520874,
            9,
            1.5,
            2.799999952316284
        ],
        "Flash": 16,
        "SubsecTime": "392",
        "CompositeImage": 2,
        "DigitalZoomRatio": 3,
        "SceneType": 1,
        "ApertureValue": 1.1699250021066825,
        "BrightnessValue": 2.820906607251797,
        "DateTimeOriginal": "2026:05:16 20:00:32",
        "FocalLength": 5.7,
        "ExposureMode": 0,
        "SensingMethod": 2,
        "FNumber": 1.5,
        "OffsetTime": "-07:00",
        "PixelXDimension": 480,
        "ShutterSpeedValue": 5.906515543357788,
        "FocalLenIn35mmFilm": 77,
        "SubjectArea": [
            1685,
            1265,
            747,
            735
        ],
        "SubsecTimeOriginal": "392",
        "ExposureTime": 0.016666666666666666
    }
    

    Cheers, Daniel

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

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