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,711 through 1,725 (of 3,011 total)
  • Author
    Search Results
  • #42098
    David Gold
    Participant

    I have a Script that used to work perfectly but has stopped working in recent versions of Tap Forms and can’t workout why.

    The script is supposed to take a search term from clipboard, do a search, if one result is found bring up a screen displaying the “Comments” field and also copy it to the clipboard. If multiple results are found it presents them, you pick one and then it also displays the “Comments” field of the selected one and copies it to the clipboard. What has stopped this working? I’m not getting any errors in the Console and the variable references are correct.

    var myForm = document.getFormNamed('Travel Database');
    var records = myForm.getRecords();
    var search_term = Utils.copyTextFromClipboard();
    var result_count = 0;
    var results = [];
    var selected;
    
    function copy_comments( comments ) {
        Utils.copyTextToClipboard( comments );
    }
    
    function multiple_results() {
    
        var joined = '--multiple_matches--';
        var res;
        for (res of results) {
            joined = joined +
            res.location + '::' + res.comment;
        }
        copy_comments( joined );
    }
    
    function search_records( haystack , needle ) {
    
        var location_id = 'fld-c55265c3f56b43feb423f5a198dffe6c';
        var comment_id = 'fld-141d923e785148e3aec84576c746a4a4';
        var rec;
    
        for (const rec of haystack) {
            if ( rec.getFieldValue( location_id ).toLowerCase().includes( needle.toLowerCase() ) ) {
                results.push( { location: rec.getFieldValue( location_id ) , comment: rec.getFieldValue( comment_id ) } );
                result_count++;
            }
    
        }
    
        if( result_count == 0 ){
            console.log( 'No results found!' );
        }else if( result_count > 1 ){
            multiple_results();
        }else{
            copy_comments( results[0].comment );
        }
    
    }
    
    search_records( records , search_term );
    #42059
    matt coxon
    Participant

    Hi Daniel Doh no picture !, I’ve re-attached but if it doesn’t attach the error is “ ReferenceError: Can’t find variable: record, line:(null)”
    But actually when I select the record and then test the script (prompted by your reply) it does seem to work , so maybe a non issue (user error)

    Thanks
    Matt

    #42056
    Daniel Leu
    Participant

    Assign following single line to a script field:

    record.getId();

    You might need to click on the recalculate formulas icon to get the field updated. To avoid this, you can add a dummy getFieldValue at the beginning of the script:

    var name = record.getFieldValue('fld-xxxx');
    record.getId();

    The name variable is not used, but this way, the script is triggered when something changes with the name field. Obviously, use a field that exists in your form.

    Cheers, Daniel

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

    #42052

    In reply to: Help with Scripts.

    Sam Moffatt
    Participant

    I did a video on building a script that joins a couple of values together and also shows an example of using the child records loop. Shows how to use the editor to put stuff together and also how to use extra values with the child records loop. Hopefully it’s helpful or useful.

    #42020

    In reply to: Help with Scripts.

    T.L. Ford
    Participant
    #42011

    In reply to: Help with Scripts.

    Brendan
    Keymaster

    Hi Michael,

    If both your fields are in the same form, then all you need to do is, in the Script Editor, double-click on the field you want to copy from. Tap Forms will write the code for you to retrieve the current value of that field.

    Then, look at the Snippets and double-click on the Set Field Value snippet. That’ll insert the command into your code at the cursor position that will set a value for a field.

    Here’s an example of copying a value from one field to another:

    function CopyScript() {
    
    	var from_field_id = 'fld-.....';
    	var from_field_value = record.getFieldValue(from_field_id);
    	var to_field_id = 'fld-.....';
    	record.setFieldValue(to_field_id, from_field_value);
    
    }
    
    CopyScript();

    So when the from_field is changed, whatever value was in it will be copied to the to_field.

    What you want to do with the from field value however is up to you. This is just a straight copy. But you may want to check the value, compare it with something, then set a different value into the to_field.

    #42010
    Michael Mckenna
    Participant

    Not sure if this has already been posted or seen , but it’s not showing in my list of posts so I will re post my questions.
    I am interested in understanding how scripts work and I read the dummies script lesson and still have no idea how it works. I have looked for videos on Youtube and found one that was still a bit complicated for me. I have read the definition sheets , JavaScript API sheet, that gives a brief explanation, however I am still scratching my head…. yes a really dummy.
    I have been through the script forum and I was wondering if someone could write me a simple script so I can copy and learn from there.
    Maybe theres a simple script video available… I am very much a monkey see monkey do kinda guy.
    I would like to populate a field entered on a form ,not linked, and have that field auto populate another on same form.
    Thank you for your time.
    Kind regards
    Michael

    #42003
    JB Be
    Participant

    Thank you for your certainly very valuable suggestions. Unfortunately, scripting is beyond my capabilities :-(

    #42000

    In reply to: A few questions…..

    Brendan
    Keymaster

    Hi Michael,

    1. You could do this with a Script field. You would have to write a script that looks at Field A, and then sets some value onto Field B after Field A has had its value set.

    2. Yes. There’s a Default Value option on many field types that you can specify. When you create a new record, the Default Value will be copied into the field.

    3. On macOS there’s a custom layout feature where you can place fields anywhere you want. But on iOS, the label is on the left and the value is on the right.

    4. The Mac version has an Access Controls function on a per form basis. So you can password protect a form and you can prevent people without the password from modifying it, adding, deleting, or updating records. The iOS version has a limited version of this feature where you can password protect a form and the form structure cannot be changed. But not all the other access controls.

    Thanks,

    Brendan

    #41997
    Sam Moffatt
    Participant

    Calculation fields will only let you do aggregate operations on fields that have multiple values (table fields, link to/form form on a many relationship). For numeric values there are more options but non-numeric fields generally results in a simple count.

    Scripting will give you access to each record and let you do what ever operation you need. One of the other forum members has done a Tap Forms JavaScript Scripting 101 and the Scripting 102 has a section on looping through records. You can use Javascript template strings to relatively easily build strings with text field values.

    #41996
    JB Be
    Participant

    Thank you for the clarification. I successfully copied the values (all text values) from one form into the other form via a table field, as suggested. However, in the next step, using such values together with values in other fields of the receiving form in a Calculation field seems not to work (the calculation always seems to end up into a COUNT()-function), but is crucial to my use of Tap Forms. And no, I have no knowledge of scripting, but hope/expect that this should work out of Tap Forms as is (at least I didn’t find anywhere any restriction in this direction to the contrary). Did I miss something?

    #41992

    In reply to: Multiple Search terms

    JB Be
    Participant

    Thank you for an incredibly swift response. Impressive!

    To 1. above: This unfortunately doesn’t really reply to my question. is there a regular Boolean search possible (NOT, AND, OR, Parentheses ( ), Quotes ” ”)? The popup button on the Saved Search edit popover view only explains to AND and OR. Can I enter some advanced boolean query into the ‘Search term’ entry box? If yes, what would be the syntax for such advanced queries? What about truncated search (all instances that end on ‘….searchstring’? What about wildcards? Is there somewhere a comprehensive description of all search possibilities on the Mac (I have understood that the search functionalities on iOS are limited to some extent).

    To 2. above: Ok, solves this issue. I am mostly interested in features on the Mac.

    To 3. above: Understood. I am nevertheless unhappy with the way this works.

    #41991
    Brendan
    Keymaster

    You would need to use a Script to copy the data into fields of the parent form. When you have relationships between forms, it’s basically just a reference to the records stored in the other form. So if you delete the record in the other form, you’re deleting the reference too. The same goes if you make changes.

    However, if you were to use a Table field and link the Table field to another form, when you select records from that other form, the values are copied into the Table field. So even if you delete the original record or make changes to it, it won’t affect the display of the records in the Table field. A Table field also has the added advantage that you can add additional sub-fields to it. This could be useful for example, if you had a Product form and an Order Items Table field. You could select items from the Product form that gets copied into the Order Items Table field and you could have an additional Quantity field which you can then specify what the quantity is.

    Look for my Invoice Tracking sample document in the Template Exchange forum to see an example of this in action.

    Thanks,

    Brendan

    #41989

    In reply to: Multiple Search terms

    JB Be
    Participant

    I am new to Tap Forms and I have no knowledge of Java Script (I am basically coming from early FileMaker).

    1. Is there a more comprehensive explanation available of search capabilities in Version 5.3 than the little explanation provided in the online ‘Manual’, which is just not enough. E.g is there finally regular Boolean search possible (NOT, AND, OR, Parentheses ( ), Quotes ” ”)?

    2. How do I search in Version 5.3 e.g. records in which Value A may appear in field 1 OR value B may appear in field 2, but in no case Value C appears in field C.

    3. Is there a way to avoid that after every advanced search, the search is saved and populates the side bar to the left?

    #41987

    In reply to: SQLite3 to Tap Forms

    T.L. Ford
    Participant

    The JSON files are all small (old data set, with few records). It worked on one of the files, but not the others and then stopped working on the original. I’ll circle back around to the problem and play with it more eventually. Random other trivia when you mentioned pasting JSON into a note field: I started writing a script that generates action notices that have javascript in a hidden field to link back to the original record that generated the action notice, and then on the action form, buttons to run the javascript in the field to either open the correct record or perform a specific action on the record. I had it working but then broke it and haven’t circled back to it again yet. So many fun things to do and play with!!!

Viewing 15 results - 1,711 through 1,725 (of 3,011 total)