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 - 856 through 870 (of 2,989 total)
  • Author
    Search Results
  • #47445
    Daniel Leu
    Participant

    I use several scripts as infrastructure/include scripts. They only contain function or constant definitions. Then I use runScriptNamed() to include these functions. Later, whenever I need, I can call one of these defined functions from these include files.

    So for your example, define

    function formScript(abc) {
       console.log(abc)
    }

    Then from your calling script, you do

    runScriptNamed("myIncludeScript")
    and then later
    formScript("hello")

    Cheers, Daniel

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

    #47442
    Bernie McGuire
    Participant

    you mean the Form Script will have access to a variable declared in a Field Script function ??? are all your vars global? this sounds strange to me.

    What I understand is this:
    function FieldScript() {
    var xyz = ‘123’
    form.rundScriptedNamed(‘formScript’);
    }

    Then in the Form Script:
    function formScript() {
    var abc;
    //I can set abc = xyz
    abc = xyz;
    // and now abc will have ‘123’ in it ?
    }
    This doesn’t make any sence to me thinking about rules of encapusalation. Unless there is some type of ‘Global’ tag I need to use on the variable.

    Please help
    Thanks

    #47438
    Brendan
    Keymaster

    If you setup a variable and populate it before you call runScriptNamed() then you should have access to that variable from within the script you’re running. So no parameter required.

    #47434
    Bernie McGuire
    Participant

    I want to have a Form Level Script (DoSomething) that accepts an input parm ex DoSomething(‘abc’).
    I’d like to call this script from various field level scripts using runScriptNamed(‘DoSomething’) but I do not see how to pass the value of ‘abc’ into the script on the runScriptNamed call.
    Is it possible?
    Thanks
    Bernie

    #47432
    David Schwane
    Participant

    When a date field is changed with the date picker, the field script referencing that date field gets fired twice.
    Simple repro case, just a date field (date_last_used) and field script


    var date_last_used = record.getFieldValue('fld-xxx');
    console.log("Process Excecuted "+ new Date().toLocaleString())

    change the date manually and script fires just once.
    use the date picker, and script fires twice.

    Any suggestions for workarounds?

    Attachments:
    You must be logged in to view attached files.
    #47426
    David Gold
    Participant

    I’ve had a go at some Javascript but can’t get it to work. Basically I want it to take a search term off the clipboard, do a search and get the record ID for the found item and then copy that to the clipboard. It isn’t working so could someone tell me what I have done wrong?

    var myForm = document.getFormNamed(‘Scopus RE’);
    var records = myForm.getRecords();
    var search_term = Utils.copyTextFromClipboard();
    var result_count = 0;
    var results = [];
    var selected;

    function search_records( haystack , needle ) {

    var name_id = ‘fld-90984efc3585456ab56763adff0a5228’;
    var rec;

    for (const rec of haystack) {
    if ( rec.getFieldValue( name_id ).toLowerCase().includes( needle.toLowerCase() ) ) {
    results.push( { name: rec.getFieldValue( name )
    } );
    result_count++;
    }

    }

    if( result_count == 0 ){
    console.log( ‘No results found!’ );
    }else if( result_count > 1 ){
    multiple_results();
    }else{
    copy_record.getId( results[0] );
    }

    }

    #47424
    David Gold
    Participant

    I don’t know JavaScript. I was wondering if there was a way on iOS to search a given form for a record (search either a given field or all fields – doesn’t matter) and then have tap forms open in that record? I was wondering if this is possibly via url scheme directly or if not by creating a script and then executing the script via url scheme. If the latter can someone help me with the JavaScript?

    #47423
    Daniel Leu
    Participant

    Looks like the context the script runs is different. Something Brendan will be able to answer.

    Cheers, Daniel

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

    #47420
    Daniel Leu
    Participant

    When you launch a script from a button, do you get any records when using search.getRecords()?

    Cheers, Daniel

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

    #47419
    David Schwane
    Participant

    Seeing some unexpected behavior upon further review.

    If I run the script from the Scripts menu, works fine. But fails from a button on a custom layout.

    As a test, I created a new script with a single line of code.

    console.log(typeof search);

    From Scripts menu, correctly returns object
    From button on form, incorrectly returns undefined

    This is on same search, same record, just running the script from menu vs button.

    #47416
    David Schwane
    Participant

    Is there any way to copy a photo field image to the clipboard via script?
    I can’t figure out how to retrieve the image from the blob object and then copy it to the clipboard.

    Basically need an image equivalent to Utils.copyTextToClipboard

    I can see the digest but that’s about it…


    var cover_id = 'fld-xxx';
    var cover = record.getFieldValue( cover_id );
    return cover[0];

    David Schwane
    Participant

    I have this script that returns a random record regardless if I’m on a form or a saved search. Works great but I know using try catch this way is not correct. What is a better way to resolve if I’m trying to get a form recordset or search recordset?

    Random_Record();
    try {
    var records = search.getRecords();
    }
    catch (err) {
    var records = form.getRecords();
    }
    var record = records[Math.floor(Math.random() * records.length)];
    form.selectRecord(record);

    #47411
    Brent Willingham
    Participant

    Thanks for the script Brendan. Glad to know about the new feature for a future release. If I can get this working, my goal is to share it with other land managers and ranchers in Texas for them to use. We all have to submit a report to the County at the end of each year and it can be a pain going through receipts and trying to remember everything. This could help keep things organized.

    #47409
    Brendan
    Keymaster

    Here’s the form template. The only problem with it is if you switch records, the Province pick list would not be synced with the Country selection until you actually changed the country.

    FYI, I have already built a new cascade pick list feature into the next big version of Tap Forms I’m currently working on. No ETA though. And no scripting required for it.

    Attachments:
    You must be logged in to view attached files.
    #47408
    Brendan
    Keymaster

    Here’s a script that I was messing around with that will change the Province field’s Pick List depending on the value selected from the Country field’s Pick List:

    function Province_Pick_List_Switcher() {
    
    	var country_id = 'fld-de7985c881804154b037c68dc4c24414';
    	var country = record.getFieldValue(country_id);
    	var canadian_provinces_pick_list = document.getPickListNamed('Canadian Provinces');
    	var us_states_pick_list = document.getPickListNamed('US States');
    	var province_id = 'fld-b1458c16690744129ff145f7b9607c99';
    	var province = form.getFieldWithId(province_id);
    	
    	if (country == 'Canada') {
    		province.pickList = canadian_provinces_pick_list;
    		
    	} else if (country == 'United States') {
    		province.pickList = us_states_pick_list;
    		
    	} else {
    		province.pickList = null;
    	}
    	
    }
    
    Province_Pick_List_Switcher();

    You could modify this script for your own needs. I added it as a Script Field and then hid the Script Field so it doesn’t show on the form, but it still works.

Viewing 15 results - 856 through 870 (of 2,989 total)