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,066 through 1,080 (of 3,053 total)
  • Author
    Search Results
  • #46611
    Sam Moffatt
    Participant

    The document.saveAllChanges() is after the return statement which means it never gets executed as the return statement returns control to the caller. It also looks like you’re missing a brace from the example code so I’m guessing that should have been before the function call. You can wrap the code in a back tick at the start and end to put it into code mode (or use the HTML tag):

    function Focus_Script() {
    
        /* variables for Practice Plan */
    
        var practice_date = record.getFieldValue('fld-id'); //practice date in parent form
        var OT = document.getFormNamed('Offensive Transition'); // child form;
        var offensive_transition = record.getFieldValue('fld-id'); // watches checkbox in parent form;
        var date_text = JSON.stringify(practice_date);
        let foci = [];
    
        /* variables from Offensive Transition */
    
        var OT_date_id = 'fld-id'; // date field from child record;
    
        if (offensive_transition == true) {
    
            /* Search Offensive Transition for existing date and add record if not there */
    
            var records = OT.getRecordsForSearchTerm(date_text);
    
            if (records.length !== 0) {
                console.log("DATE EXISTS ALREADY"); // true condition;
    
            } else {
    
                foci.push("Offensive Transition"); // false condition;
    
                var new_OT_record = record.addNewRecordToField('fld-id');
                new_OT_record.setFieldValue(OT_date_id, practice_date);
                console.log("DATE DOES NOT EXIST");
                Utils.alertWithMessage('Done.', practice_date + " added."); // false condition;
    
            }
        } else {
    
            /* Delete existing record for a given date in Offensive Transition */
    
            var OT_records = OT.getRecords();
            var field_id = 'fld-id';
            /date field converted to text;
            for (var index = 0, count = OT_records.length; index < count; index++) {
                var aRecord = OT_records[index];
                var field_value = aRecord.getFieldValue(field_id);
                if (field_value == date_text) {
                    OT.deleteRecord(aRecord);
                }
            }
        } // false condition;
    
        document.saveAllChanges()
    
        console.log("EOJ");
        return foci;
    }
    
    Focus_Script();
    #46610
    Mark Kearney
    Participant

    Hello. Basic programmer here (literally, my understanding comes from my days with BASIC).

    I am trying to create a basketball season practice planner where clicking a checkbox for a practice topic automatically adds a record to a “Link To” field (joined by date field). The details for the parent topic can be stored in the child record. The practice topic from the parent form is then stored in array (foci) along with the other topics for that practice. If the checkbox is unchecked, the records in the child form are deleted for a given date and that topic is removed from the array.

    This portion of the script (located in a field in the parent form) appears to work but the new child record does not appear in the linked field until records are refreshed. NB: There is a script in the child form that converts the date to text (as with var date_text below) for the search piece.

    I would like to get the child record to show in the “Link to” field without needing to refresh. Any help would be greatly appreciated.

    function Focus_Script() {

    /* variables for Practice Plan */

    var practice_date = record.getFieldValue('fld-id'); //practice date in parent form
    var OT = document.getFormNamed('Offensive Transition'); // child form;
    var offensive_transition = record.getFieldValue('fld-id'); // watches checkbox in parent form;
    var date_text = JSON.stringify(practice_date);
    let foci=[];

    /* variables from Offensive Transition */

    var OT_date_id = 'fld-id'; // date field from child record;

    if (offensive_transition == true) {

    /* Search Offensive Transition for existing date and add record if not there */

    var records = OT.getRecordsForSearchTerm(date_text);

    if (records.length !== 0) {
    console.log("DATE EXISTS ALREADY"); // true condition;

    } else {

    foci.push("Offensive Transition"); // false condition;

    var new_OT_record = record.addNewRecordToField('fld-id');
    new_OT_record.setFieldValue(OT_date_id,practice_date);
    console.log("DATE DOES NOT EXIST");
    Utils.alertWithMessage('Done.', practice_date + " added."); // false condition;

    }
    } else {

    /* Delete existing record for a given date in Offensive Transition */

    var OT_records = OT.getRecords();
    var field_id = 'fld-id'; /date field converted to text;
    for (var index = 0, count = OT_records.length; index < count; index++){
    var aRecord = OT_records[index];
    var field_value = aRecord.getFieldValue(field_id);
    if (field_value == date_text) {
    OT.deleteRecord(aRecord);
    }
    }
    } // false condition;

    console.log("EOJ");
    return foci;
    document.saveAllChanges()

    Focus_Script();

    #46606
    Rob Naaijkens
    Participant

    Hi Sam,

    First, thank you very much for all this effort, appreciate that!

    I had a link between the second and the first. But not between the first and second.

    I used your script but got some errors. Now I still got an error on the script for the second form. Is there a possibility to copy my database and send it to you by e-mail (WeTransfer) so you can take a look?

    Attachments:
    You must be logged in to view attached files.
    #46602
    Sam Moffatt
    Participant

    At the moment it doesn’t look like you’ve got any links between the two?

    The function doesn’t work because first nothing calls it (you need a getTotalofLinkedFieldForField(); at the end of the script) and second linkedRecord is not defined.

    Since there isn’t a link between the two forms, we’ll automate populating the other form. We’re going to use form.getRecords to get a copy of all of the records in the current form (there are a bunch of other examples on the forum as well), get the total and populate that into the other form. We’ll create this script inside the first form since it’s the source. You’ll need to swap in the field IDs from the place holders:

    var firstForm_NaamFieldId = 'fld-naamfield';
    var firstForm_tableFieldId = 'fld-4dde0c4712954541a69b18d602bfcb27';
    var firstForm_tableField_subFieldId = 'fld-60216b72e69b4a9bab98a23c8a019ea9';
    
    var secondForm = document.getFormNamed("Nieuw formulier");
    var secondForm_NaamFieldId = 'fld-namefield';
    var secondForm_NummerFieldId = 'fld-nummerfield';
    
    function Create_Summaries() {
    	// get all of the records from the current form (should be first form)
    	for (let currentRecord of form.getRecords()) {
    		// create a new record for it in the second form
    		let linkedRecord = secondForm.addNewRecord();
    
    		// copy the name across
    		linkedRecord.setFieldValue(secondForm_NaamFieldId, currentRecord.getFieldValue(firstForm_NaamFieldId));
    
    		// create the total value field
    		linkedRecord.setFieldValue(secondForm_NummerFieldId, currentRecord.getTotalofLinkedFieldForField(firstForm_tableFieldId, firstForm_tableField_subFieldId));
    	}
    
    	// save all changes
    	document.saveAllChanges();
    }
    
    Create_Summaries();
    

    Though ideally you’d set up a link to form field to keep them together. If you create a link to form 1:M from your first form to your second form and then tick “show inverse relationship”, you can create a script field in your second form that looks like this:

    var firstForm_tableFieldId = 'fld-4dde0c4712954541a69b18d602bfcb27';
    var firstForm_tableField_subFieldId = 'fld-60216b72e69b4a9bab98a23c8a019ea9';
    var secondForm_linkFromFormFieldId = 'fld-linkfromformfieldid';
    
    function TotalValue() {
    	let linkedRecord = record.getFieldValue(secondForm_linkFromFormFieldId);
    	return linkedRecord.getTotalofLinkedFieldForField(firstForm_tableFieldId, firstForm_tableField_subFieldId));
    }
    
    TotalValue();
    

    Though for that to work you will need that link to form field setup. Give that a spin and see how it goes.

    #46596

    In reply to: Inventory Script

    Sam Moffatt
    Participant

    Random thought: you could go crazy with a few more forms but it feels like at least “purchase point” should be it’s own form (you could do a form for brewery, styles and sizes as well then use links but that might be overkill?). Purchase point is definitely a candidate for it’s own form and I think sizes might help as well because it seems like you’d have standard sizes.

    I did a tutorial on managing balances with Tap Forms using yarn balls as an example and products like hats. There are two videos, the first video sets the ground work forms and has a simple script for setting the balance whilst the second video walks through building the scripting to add and remove entries maintaining the balance. These should help you handle reducing the inventory quantity when applying new parts but it does rely upon form scripts to work properly.

    In your case you still need to have something that figures out the quantity you want to reduce by for the purchase points to make it work properly. That might just be a simple prompter entry that then creates the entries for you automatically. I personally use prompters a lot for quick entry of information which speeds up data entry because I can hit the three fields I need rather than load up an entire form.

    #46594

    Topic: Inventory Script

    in forum Script Talk
    Neil Bontoft
    Participant

    I have what I think is a very simple question but I sadly haven’t got a clue how to answer it.

    I use Tap Forms v5 as a tool to record inventory in my cellar. Columns include:

    • Brewery
    • Beer
    • Size
    • Style
    • Purchase Point

    I would like to monitor the quantity of each bottle. It’s not as simple as using an integer and increasing or decreasing as fields like Purchase Point can vary depending on where the bottle was bought.

    I have created a concat field that combines Brewery, Beer and Size. This field effectively creates a string for the unique beer which I think could be used.

    I guess I have two options:

    • A field script that for each record (circa 900) could check if the concat field equals other concat fields and count as appropriate.
    • A new form which uses the concat field and does a count against each record for the concat field. To do this I would also need the script to copy the concat field, and remove any with zero quantity.

    Advice is massively appreciated. Cheers

    • This topic was modified 4 years, 2 months ago by Neil Bontoft.
    #46588
    Kirk Williams
    Participant

    Thank you so much Sam! I will definitely need to spend some time with this (given my limited scripting experience), but this is precisely the type of logistic advice I was hoping for.

    Your time and guidance are very much appreciated!

    #46584
    Rob Naaijkens
    Participant

    Maybe some more information on what I am trying to do.

    First Form: (Assortiment wijnen) all unique records with a Table field “Verkocht” in that table there are 3 records at the moment. The total of the record with “Aantal” I would like to show-up in the second form.

    I would like to use the table because these are wines and I would like to see the price per year of period.

    Second Form: This is where I would like the total of all the “Aantal” records from the first form.

    On your explanation I made the following script. First ID is the field “script” itself and the second is the ID of the field “Aantal” form the first form.

    The script works, no errors but the result on both numbers and text is nothing or <empty>.

    Hope this makes any sense ;)

    Attachments:
    You must be logged in to view attached files.
    #46583
    Rob Naaijkens
    Participant

    Hello Sam,

    Thanx for the quick reaction! Is it possible to tell me the complete code of the script? I’m a beginner ;)

    I like to try your solutions and will post the results later.

    #46581
    Sam Moffatt
    Participant

    Do you mind expanding a little on your structure?

    If you’ve got a link from the second form to the first, you can create a script field that traverses the link to form field (actually might be easier to do it as a link from form field) and then you can call linkedRecord.getTotalOfLinkedFieldForField(tableFieldId, fieldInTableId) to get a total of the field in the table (first ID is the ID of the table field itself, second one is the ID of the field you want to get the total of in the table). This actually becomes a one liner if you only have a 1:1 style mapping with the second form (link to form 1:M from the first to the second will give you a singular relationship in the second form). If there is a many relationship from the second form to the first, then you’ll need to get all of the linked records, loop over them, get the total and then sum it together.

    If you’ve going to programatically populate the second form, then that’s a loop to create the record and the same getTotalOfLinkedFieldForField on the source record to calculate the total of the field in the table field.

    Share a little about how the two forms are linked (or not) and how you interact with the two forms. The CRM video I did recently has a bunch of fun with linking forms together as well.

    #46580

    In reply to: Help with a script

    Sam Moffatt
    Participant

    If you post your scripts to date and maybe the form template folk on the forum can probably help. One of the cool things about the forum is that everyone can benefit from your questions and any solutions :)

    #46579
    Sam Moffatt
    Participant

    When you use Siri Shortcuts, you need to use the x-callback-url feature to load Tap Forms to trigger the document interaction. I did a video on using the x-callback-url to trigger a script from Siri Shortcuts. Otherwise I believe it invokes Tap Forms in the background (via a library I think?) and doesn’t permit any interaction with scripting. The Siri interactions API is kind of limited in what it allows so if you want any sort of interactive experience, I’ve only really seen it possible via the Shortcuts app.

    #46577
    Stig Widell
    Participant

    Hi,
    Is anyone willing to help a Swedish farmer with a record script in his cow data base?
    No knowledge in JavaScript!
    Brendan Duddrige has helped a lot with two earlier scripts but is too busy now for a third one.
    Will send document via e-mail.
    Regards
    Stig Widell

    #46574
    Rob Naaijkens
    Participant

    I have a series of records with a Table Field. I would need to use their total value in a second form. Is it possible with scripting? And if so, what is the way to do this?

    #46571
    Prashant M
    Participant

    Dear Daniel , I will definitely use back-ticks and link to the post

    Thanks for the script , It works properly on my OSX also when I try to use the same on iPhone manually it works (via Scripts->RUN)

    BUT if I add the script to Siri Shortcuts , I simply get a DONE message and no prompt to enter. Please see screenshot attached for the same.

    Dear Sam, Thanks for the link , I’ve installed the same on OSX , and I see 19 scripts :) I will be studying these and updating !

    Attachments:
    You must be logged in to view attached files.
Viewing 15 results - 1,066 through 1,080 (of 3,053 total)