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 - 16 through 30 (of 3,110 total)
  • Author
    Search Results
  • Kevin Winspear
    Participant

    I’ve been experimenting with Tap Forms Pro’s scripting capabilities and wanted to share a workflow I’ve been using successfully.

    One of my goals was to avoid having my data locked into any single application. I use Tap Forms as my structured database, but I also use Obsidian for note-taking and knowledge management.

    Using a Tap Forms script, I’ve set things up so that whenever I add or update a record, a Markdown (.md) file is automatically generated and written directly into my Obsidian vault.

    For example, in my Movies database, the script creates a note containing:

    * YAML frontmatter
    * Movie metadata (title, year, rating, tags, etc.)
    * Cover image references
    * IMDb links
    * Description and cast information

    The generated note is immediately available in Obsidian without any manual export step.

    A simplified workflow looks like this:

    Tap Forms Record
    → Metadata Updated
    → Script Runs
    → Markdown File Generated
    → Obsidian Vault Updated

    One advantage is that my information remains portable. The data exists in Tap Forms, but I also have a complete set of Markdown files that can be used in Obsidian or any other Markdown-based application.

    I’ve now started using the same approach with several of my Tap Forms databases, not just movies.

    I’m posting this partly because I think Tap Forms’ scripting features are incredibly powerful, and partly because there may be other users interested in integrating Tap Forms with Obsidian or other Markdown-based workflows.

    If there’s interest, I’d be happy to share more details about the script and how I set everything up.

    #54241
    Daniel Leu
    Participant

    This shouldn’t be difficult to do with a script. Would you be willing to share your Tap Forms template with me? (You can find it under File > Export > Form Template (TFF). If you’d rather, feel free to email it to me. Once I have the template, I’ll give it a shot.)

    Cheers, Daniel

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

    #54238

    In reply to: Using tablefields

    Steve-Kai Vyska
    Participant

    Sorry for the late Answer was messing around with the scripts. Yes it is working 👍

    #54237
    Brendan
    Keymaster

    Your best bet for now would be to export your records to an Excel spreadsheet and then import it into Excel (or Numbers) and do some summarization there. At the moment I don’t have a function that would do that. Tap Forms will compute totals for each category, but it will also display the details.

    But of course you could write a script for it to just dump out the summary data in the console. But it would be easier for you to use Excel. Especially if you’re not familiar with scripting.

    Thanks,

    Brendan

    pierrot_rennes
    Participant

    Hello,

    I have a database with 5185 records in 58 categories.
    It’s a collection of comic book puzzles, and the different categories correspond to the comic book titles, as shown in the screenshot.
    In the database, there are two scripts that highlight puzzles in the collection and those that are incomplete (scripts created by a form user at least 6 years ago).
    I would like to automatically retrieve the number of puzzles in the collection and the number of missing puzzles for each category into a table.
    I don’t know if this is possible with a script, and I don’t know how to do it either, as I’m not familiar with scripting.
    Thank you for your information, and perhaps it’s not feasible. The screenshots show my database, the relevant fields, and a table as it could be created.

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

    In reply to: ordinal day?

    Glen Forister
    Participant

    I got the script to work, thanks. BUT, not all dayofyear values are the same for multiple records of the same day. What does that, to be off a day?
    Thanks for sticking with me on this.

    Attachments:
    You must be logged in to view attached files.
    #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 2 months ago by Daniel Leu.
    • This reply was modified 2 months ago by Daniel Leu.
    • This reply was modified 2 months 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 months, 1 week 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

Viewing 15 results - 16 through 30 (of 3,110 total)