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 2,979 total)
  • Author
    Search Results
  • #53284
    Shane
    Participant

    Thanks for the reply.

    I did read that documentation, but isn’t that used to add a child record to a parent record? I was referring to changing the parent record to the child record.

    I guess if I wanted to copy template children to a new parent I could do it that way. I could use a script to essentially copy the child record info from a template parent record and recreate those children records under the new project name. However, I am still curious if you could use a script to change the parent record of a child record. :)

    • This reply was modified 3 weeks, 4 days ago by Shane.
    Daniel Leu
    Participant

    Looks like you’re using TapForms5.

    Sometimes ChatGPT does a good job, sometimes it hallucinates and creates strange recommendations like inventing nonexisting API functions. In your script, you should add a document.saveAllChanges(); before you the return statement.

    Happy coding!

    Cheers, Daniel

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

    #53282
    Daniel Leu
    Participant

    I agree, the scripting feature is very powerful. Without it, I wouldn’t use TFP.

    You can add a linked record using var newRecord = record.addNewRecordToField(field_id); and to remove an existing record there’s record.removeRecordFromField(childRecord, field_id');. Here’s the link to the documentation https://www.tapforms.com/help-mac/pro/en/topic/javascript-api.

    Cheers, Daniel

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

    #53279
    Shane
    Participant

    Hey all, so far I’m excited about the power of scripting in TapForms and am trying to put it to good use.

    I’m trying to create a template system where I can copy/move placeholder records to a new parent record. Normally to assign a child record to parent record you would click the “Select and link existing records” object/ button which would bring up the possible parent records for reassignment (see screenshot). I’m wondering if this could be done through scripting.

    In this example I have a Clients parent form linked to a child Projects form.

    You can seem to access the parent record by doing the following (see second screenshot):

    function Reassign() {
    
        var clients = record.getFieldValue('fld-25ab19edf2014cc0952446ed09975851');
        console.log(clients);
    }
    
    Reassign();

    Console shows a record object:

    2025-11-23, 8:02:35 AM / Projects / Reassign
    [object CDRecord]

    So can we somehow code a different parent record for the child record somehow?

    Thanks.

    Attachments:
    You must be logged in to view attached files.
    Melanie Schaaf
    Participant

    Thanks for the tip Daniel!

    Unfortunately I wasn’t able to make your approach work, but I might not have implemented it correctly. I am a very beginner level script-writer.

    However, while I was looking for a solution in the forums last night, I found out that there is a custom GPT on ChatGPT and with its help I was able to fix the script and now it works on a 1:M relationship.

    The problem was that while a linked form in an M:M relationship returns an array of records and while in a 1:M relationship the form also returns an array on the “Many”side, it does not return on array on the inverse relationship side, as there is always only one record.

    The corrected script (with the aid of the Chat GPT assistant) now also extracts several fields with no problems:

    function Extraction_Collection_Data() {

    // get the linked parent record (ONE record in 1:M)
    var collection = record.getFieldValue(‘fld-9be76f6c90334bbbaa0e2c4dc3556358’);

    // destination field IDs in Embroidery Designs
    var entire_collection_on_file_id = ‘fld-ef5768afe70c46968999aae8f538aa65’;
    var collection_series_id = ‘fld-ee2bff7b5d8f4e7f80797e6ad144dc33’;
    var collection_series_photo_id = ‘fld-a1b6349df4124933a70abb6dd30728d5’;
    var collection_website_id = ‘fld-cb6dd1f0e77c4fbcba331141ecd66d5d’;

    // — CASE 1: no linked collection (collection == null)
    if (!collection) {

    record.setFieldValue(entire_collection_on_file_id, ”);
    record.setFieldValue(collection_series_id, ”);
    record.setFieldValue(collection_series_photo_id, ”);
    record.setFieldValue(collection_website_id, ”);

    return;
    }

    // — CASE 2: a single linked parent record exists

    var entire_collection_on_file = collection.getFieldValue(‘fld-c0f51c1134e84335aaf27c64fa0c0bf1’);
    var collection_series_name = collection.getFieldValue(‘fld-40cb304839354352875dcaefb9403a2f’);
    var collection_package_photo = collection.getFieldValue(‘fld-0ed3dcb5bf194e3996de901f86a390d5’);
    var collection_website = collection.getFieldValue(‘fld-40ed47e24443496b9e0bdfd9831ff570’);

    record.setFieldValue(entire_collection_on_file_id, entire_collection_on_file);
    record.setFieldValue(collection_series_id, collection_series_name);
    record.setFieldValue(collection_series_photo_id, collection_package_photo);
    record.setFieldValue(collection_website_id, collection_website);
    }

    Extraction_Collection_Data();

    I am very happy with this solution and can only recommend using the ChatGPT assistant for basic scripting help. For me it worked brilliantly!

    Shane
    Participant

    I remember doing this in MS Access where you could link / join more than one field from the parent to child table (form). In TFP it would open up a few very cool possibilities such as the ability to show/ edit/ create subsets of records.

    So for example, if you link a Project Field AND a Client Field to a child Tasks Form, it would auto-populate the Client and Project fields in the tasks form if you added a record.

    Similar in purpose, it would be cool to be able to use something like a “Link to” field to connect to a pre-created search. I know you can use Javascript to access Search records, but it would be easier for people to do it with a “Link to” field (or whatever it could be called). Clicking on the populated records would go to that set of (search result) records for editing. I feel adding records from this type of hypothetical field wouldn’t be possible because of the complexity of the user inputted search criteria.

    Thanks for reading.

    • This topic was modified 3 weeks, 5 days ago by Shane.
    #53270
    Daniel Leu
    Participant

    The only thing I noticed is your return statement. Try to replace it with return done;.

    Since it’s the reverse relationship of a one-to-many, you could use a calculation field as well.

    Here’s a script for a single value, although it doesn’t contain any error checks: https://www.tapforms.com/forums/topic/totally-lost-on-script/#post-53221

    Cheers, Daniel

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

    Melanie Schaaf
    Participant

    Hi,

    I have run into a problem extracting data from a Link to Form-field with a One to Many-relationship.

    I usually use Many to Many-relationships in my database, which is probably why I’ve never had this problem before. What I am trying to do is use a script to extract data from a certain field in a linked form and display it in a script field, because I can format that to match my layout.

    What I usually do with a Many to Many-related form is this:

    function Collection_Series() {

    var embroidery_collections_id = ‘fld-9be76f6c90334bbbaa0e2c4dc3556358’;
    var collection_series_name_id = ‘fld-40cb304839354352875dcaefb9403a2f’;

    var childs = record.getFieldValue(embroidery_collections_id);

    var child_names = [];
    for (child of childs){
    child_names.push(child.getFieldValue(collection_series_name_id));
    }

    //child_names.sort();
    var done = child_names.join(‘, ‘);
    console.log(done);

    return (done);

    }

    Collection_Series();`

    Now, I am aware that this script is designed for multiple values to be returned, from multiple linked records. But this should also work for a single record from a One to Many-relationship…

    But it doesn’t work. I should say that I am using this on the reverse relationship variable, so basically on the “One”-side of the One to Many-relationship.

    Can anyone help me perhaps with a different method to extract that value from the linked record?
    Like I said, it is simply an aesthetic problem; I don’t like the look of Link to Form-Fields in a layout and I really just want to display the value and not the control elements, because I will be linking records from. the other side.

    I might as well just use a Many to Many-relationship, but I feel like there should be a way to do what I am trying to do with a One to Many-relationship as well.

    Thanks in advance!

    Shane
    Participant

    I think this could be a tough feature to implement, but it would be cool if we could sort a subset of records in a link-to-form scenario. The manual sorting works for records in an entire form, but will not do anything if you drill down via a link to form field.

    So for example, you have a form called “Projects” then have a child form “Tasks” via a link-to (one to many relationship) field. By clicking a task in the Link To field in the project form layout it will go to the task, and show all the other tasks related to that project.

    It would be very useful to be able to manually sort these tasks within this collection of records. Right now I use scripts to promote / demote the tasks with a numeric “order” field which works, but a manual sort would be much easier to implement going forward. :)

    Attachments:
    You must be logged in to view attached files.
    #53247
    Shane
    Participant

    Has anyone noticed in TFP that setting a menu shortcut for a script doesn’t work? I’ve tried different shortcuts and made sure that it’s not sharing a shortcut with another menu item. I feel it might be a macOS Tahoe thing? I’ve included a screenshot to show what the shortcuts looks like.

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

    In reply to: Totally lost on script

    Daniel Leu
    Participant

    For completeness, this is how the script would look like.

    function Script() {
    
        const property_id = 'fld-xxx'; // set according to your form
        const ownerName__property_id = 'fld-xxx'; // set according to your form
    
        // get properties record 
        // (the result is an array, but since it's a one-to-many relationship, just take the first entry)
        const property = record.getFieldValue(property_id)[0];
    
        // get owner name 
        const ownerName = property.getFieldValue(ownerName__property_id);
    
        return ownerName;
    }
    
    Script();
    

    For this to work, the reverse relationship option needs to be set and the return type of the script must match the field type from the property form.

    Cheers, Daniel

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

    #53219
    john bluma
    Participant

    I have two forms
    Parent form- Property. Fields PropId and OwnerName. One to many link to child.
    Child file Payments. Fields PaymentFor and Payee

    I would like to copy. PropId -> PaymentFor. and OwnerName -> Payee
    automatically when the child record is created.

    I have lloked at other posts in this forum and I just don’t get it.
    Can you help me get started on this?

    #53211
    Tap forms Forum
    Participant

    Prompting for input seems to be broken (on iPadOS) on 1.0.12
    This super basic test-script works on my old iPad running 1.0.10, but seems to exit as soon as it hits the prompt on my current iPad running 1.0.12

    function Script() {
    var text_field_id = ‘fld-fbb43c119bb24512a7599b04d335d3b6’;
    var check_mark_id = ‘fld-c164df88f01746b4a476462fd89ab696’;
    var check_mark = record.getFieldValue(check_mark_id);

    if (!check_mark) {
    return;
    }

    var callbackFunction = function() {
    console.log(value_1);
    record.setFieldValue(text_field_id, value_1);
    record.setFieldValue(check_mark_id, false);
    };

    let prompter = Prompter.new();
    prompter.addParameter(‘Label 1’, ‘value_1’, ‘text’)
    .show(‘Message prompt’, callbackFunction);
    }

    Script();

    Backup of the document attached just in case

    #53183
    Stephen Pickard
    Participant

    I am trying to do something similar. Get a script to set a value in a linked field. Tried many things without luck including the above. I can’t even get a value from the “Mob” field when it is set. The attached image shows what I am trying to do.

    Attachments:
    You must be logged in to view attached files.
    #53150
    Keith
    Participant

    After updating to iOS Tap Forms version 1.0.12, I’m unable to add records with a script. The script still works on the macOS version, though I haven’t updated to 1.0.13, yet.

Viewing 15 results - 16 through 30 (of 2,979 total)