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 - 61 through 75 (of 3,016 total)
  • Author
    Search Results
  • 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.

    #53112

    In reply to: Performance?

    Brendan
    Keymaster

    Hi John,

    No, that’s not normal.

    Maybe try running the Re-build Search Index function in the Tools menu. Do you have any Script Field or Calculation Fields that are run when you edit your Note fields? That could cause a delay.

    Thanks,

    Brendan

    #53082
    Brendan
    Keymaster

    Glad you figured it out. Just re-reading your script a little more closely you did define the same checkmark variable name with two different IDs and your final version shows different variable names, which is correct.

    Sorry I didn’t examine it more closely before.

    A loop is the for (....) { } structure in your code. You don’t want the call to save within that because it’ll cause a refresh every iteration through the loop.

    I’m glad you figured it out.

    Sometimes programming is just trial and error. But through each iteration, you learn more and know what to look for the next time so you don’t make the same mistakes again.

    #53080
    David White
    Participant

    Hey Guy’s I got this thing working now. I researched through Google AI. It took a ton of trial and error… but i finally got it. Remember in the javascript… Reset Check was my form i made. Day 1 and Day 2 was my checkboxes. Blank was the name of my Script.

    I just wanted to click on my script ( named Blank ) one time, and Day 1 and Day 2 checkboxes ( In ALL my records at once ) would reset. The following pasted javascript does that for me now.

    // Function to clear all checkbox fields in every record
    function BlankAllRecords() {
    // Get all records from the current form
    var allRecords = form.fetchRecords();

    // Field IDs for your checkboxes. These are unique to your form.
    var day1FieldId = ‘fld-f9318c6c66944131b69e29e75ab996db’;
    var day2FieldId = ‘fld-3adc2a737f9f468b8bb6be8327c9139d’;

    // Loop through each record in the form
    for (var i = 0; i < allRecords.length; i++) {
    var aRecord = allRecords;

    // Set the value of the checkbox fields to 0 (unchecked) for the current record
    aRecord.setFieldValue(day1FieldId, 0);
    aRecord.setFieldValue(day2FieldId, 0);
    }

    // Save all changes after looping through all records
    document.saveAllChanges();

    // Optional: Add a message to the console for debugging
    console.log(“All records have been reset.”);
    }

    // Run the function
    BlankAllRecords();

    Hope this helps others in some small way.
    Thanks Shane and Brendan.
    God Bless guys.

    #53077
    David White
    Participant

    I’m not totally clear what a loop is. But I think I got it out of the loop. I’ll paste what I did here. If I did it right… the script still is not working. It’s doing the same thing… It’s only blanking out Day 2 checkmark, and not Day 1 checkmark.

    Here’s what I did.

    function uncheckRecords() {

    // get the ID of the form you want to get the records from
    var myForm = document.getFormNamed(‘Reset Check’);

    // get the ID of the checkbox field
    var checkMarkField = ‘fld-f9318c6c66944131b69e29e75ab996db’;
    var checkMarkField = ‘fld-3adc2a737f9f468b8bb6be8327c9139d’;

    // get the records from that form
    var records = myForm.fetchRecords();

    // iterate through all records and set the charkMarkField to unchecked
    for (var index = 0, count = records.length; index < count; index++){
         // pull single record from array:
         var theRecord = records[index];
         // change field value for that record
         theRecord.setFieldValue(checkMarkField, 0, false);
    }
    document.saveAllChanges();
    }
    uncheckRecords();

    #53071
    David White
    Participant

    Oh… so close. I made the change: myForm.getRecords()… to: myForm.fetchRecords().

    It stopped the Error Message, and when i clicked on the script it even unchecked one of my two check boxes. It unchecked: Day 2. But not: Day 1.

    I will copy and paste here my script. Hope it helps make sense of it. In the script… First Field ID is Day 1. Second Field ID is Day 2. ( Only Day 2 checkbox resets ). My script below.

    function uncheckRecords() {

    // get the ID of the form you want to get the records from
    var myForm = document.getFormNamed(‘Reset Check’);

    // get the ID of the checkbox field
    var checkMarkField = ‘fld-f9318c6c66944131b69e29e75ab996db’;
    var checkMarkField = ‘fld-3adc2a737f9f468b8bb6be8327c9139d’;

    // get the records from that form
    var records = myForm.fetchRecords();

    // iterate through all records and set the charkMarkField to unchecked
    for (var index = 0, count = records.length; index < count; index++){
         // pull single record from array:
         var theRecord = records[index];
         // change field value for that record
         theRecord.setFieldValue(checkMarkField, 0, false);
         document.saveAllChanges();
    }

    }

    uncheckRecords();

    #53070
    Brendan
    Keymaster

    try myForm.fetchRecords(). In Tap Forms Pro I had to rename the getRecords() function to fetchRecords().

    Sorry, I missed seeing that in the script above.

    #53069
    David White
    Participant

    Hello Shane and Brendan.

    First I want to thank you both for your help.

    I got scared I was going to mess up my CWL WARs Form … so I made a practice form that does kinda the same thing.

    My practice Form is called: Reset Check. And I made only two checkboxes name: Day 1 and Day 2.

    I put your Script in and where it says:
    Var myForm = document.getFormNamed( ‘Reset Check’);

    As you can see I put: Reset Check.

    I put in the IDs For: Day 1 and Day 2.

    Everything seems to work … except I get this message that pops up:

    ERROR
    TypeError: myForm.getRecords is not a function. ( In ‘myForm.getRecords(); ‘myForm.getRecords’ is undefined), line:(null)

    I have no idea what that means. I was hoping it would work. I don’t know what to do to fix that.

    Hoping you might have a trick up your sleeve that can make this script work.

    Note: As I mentioned in the beginning… I only use IOS iPhone and iPad. I don’t have a Max Lap Top. Hoping it doesn’t matter. I am using Tap Forms Pro app i purchased. Thats why i chose this Forum. If i’m not suppose to be here… let me know. I will post my questions where i’m told to go.

    Thanks.
    God Bless.

    #53068
    Brendan
    Keymaster

    Looks good to me Shane. Just make it as a Form script and run it whenever you want to uncheck all the records in the form. It won’t run automatically when the form is viewed.

Viewing 15 results - 61 through 75 (of 3,016 total)