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 - 2,266 through 2,280 (of 3,011 total)
  • Author
    Search Results
  • #37946
    Brendan
    Keymaster

    Hi Joshua,

    That would require routing information. There’s probably a Google API you can use to get the mileage given two end-points. But you’d have to do some research on that. You can use a Script to call out to a web service API and get the results which you could then store back in Tap Forms.

    The Scripts topic in the online manual has an example of calling an online UPC web service that retrieves movie details. It would give you an idea how to call out to a web service. You just have to find the right web service to give you the results you’re looking for.

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    The script I wrote for this mileage tracker simply copies the odometer reading from the selected record to a new record, then selects the new record.

    #37938
    Joshua Kroll
    Participant

    Thanks Brendan,

    Different question: I’m not good with scripting, but I thought maybe something may already exist that takes this a step further. Do you know if there is a script that I can put in a preset “start” address so that when I put in the destination, the milage is populated automatically?

    I do a LOT of driving and need to track the milage. Something that simple would be awesome!

    Just started with the iOS version and am very impressed so far! Thanks for a great product and great support.

    Best,
    Josh

    #37935
    Sam Moffatt
    Participant

    I had a play with this and decided to use the new 5.3.7 clipboard support. I broke it up into three scripts: a launcher form script called Open AppleScript, the AppleScript itself and then a Land AppleScript to print the record ID.

    I used openUrl and this seemed to work ok. I also added a file attachment to a form and then attached the app to it to see if this would get around the Mac file limitation. This seemed to work for me but I didn’t try a fully sandboxed MAS version.

    The AppleScript I converted into an application to let Tap Forms launch it. This seemed to work fine. I modified your script to not re-open the same document since in this case it was open already to start the script and opening the document again was causing TF to open the document twice.

    The last bit just validates that the clipboard is fine. Obviously if you use the clipboard along the way it won’t work properly but I think for this use case maybe it’d be ok? Even if you did use the clipboard in your ApplesScript, you could format it in such a way that the Tap Forms script could process it and make sense of it.

    Of course we could just wait for the next Tap Forms release where it’s fixed but where’s the fun in that?

    The Open AppleScript:

    Utils.copyTextToClipboard(record.getId());
    Utils.openUrl('file:///Users/pasamio/Documents/argv.app/');
    

    The AppleScript:

    tell application "Tap Forms Mac 5"
    	set theDialogText to "Running AppleScript!"
    	display dialog theDialogText
    	set doc to document "Test-TemplateImport.tapforms"
    	run doc script named "Land AppleScript" in form "AppleScript"
    end tell

    The Land AppleScript form script:

    Utils.alertWithMessage('Remote ID', Utils.copyTextFromClipboard());
    
    #37933
    Sam Moffatt
    Participant

    A form script like this should do it (replace check_mark_id with your field ID):

    var check_mark_id = 'fld-acaa569a30294a02a26e6fb116781718';
    var records = form.getRecords();
    var checked = 0;
    for (record of records)
    {
    	checked += record.getFieldValue(check_mark_id);
    }
    
    checked / records.length * 100
    #37926
    Roy McKee
    Participant

    Does anyone have a sample script to calculate the number of ticked check box rows as a percentage of the total number of rows?

    #37918
    Daniel Leu
    Participant

    How about having one additional TF script that you launch before you start your Automator/AppleScript flow? In this script, you would store record.getId() in a dedicated form ‘workaround’ with one field: currentRecordId. Then in your TF script called via AppleScript, first you would restore the current record based on currentRecordId fetched from the ‘workaround’ form.

    Again, this is only a workaround until TF sets record when being called from an external AppleScript.

    Cheers, Daniel

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

    #37917
    Martin Inchley
    Participant

    Isn’t that circular? I would need to know the record ID for the current record – but there’s no way of knowing what that is. I can only use this snippet if I know in advance which record I want to target.

    I want to be working on a record in TF, and then invoke a workflow in Automator/AppleScript which involves a TF script referencing the TF record I’ve been working with.

    #37905
    Brendan
    Keymaster

    Hi Martin,

    You’ll just have to get the specific record first in the script:

    var thisRec = form.getRecordWithId('rec-93d0352d75c64a638dced9515827ac95');

    #37902

    In reply to: Time delay in scripts

    Grant Anderson
    Participant

    Agreed! And yeah, I’m using it as a form script as it is post-processing hundreds of records based on web lookups.

    #37890
    Sam Moffatt
    Participant

    You need to assign a variable which is the record from the other form first.

    In the Script Editor, double click on the form name to get it’d field ID and then use var otherform = record.getFieldValue('fld-id') to get the linked records. If this shows up in Tap Forms as a table then you’re going to get an array of records (1:M in the parent, M:M fields or JOIN fields), if you’re in the child of a 1:M relationship then you will get a single record (the parent).

    Then you can get the value of the fields from that record via the other form, e.g. otherform[0].getFieldValue('fld-otherid').

    #37886

    In reply to: Time delay in scripts

    Sam Moffatt
    Participant

    Even if setTimeout existed, it’d require the Javascript execution to be fully async but that would then cause potential race conditions with other scripts executing and changing values. It might make sense for form scripts but making that async in an environment like Tap Forms is a recipe for hard to debug issues that would make any seasoned operations person have nightmares.

    I have a similar use case of a large amount work that a form script is doing which pauses Tap Forms due to doing heavy network I/O. Some sort of progress bar interface that I could use to at least communicate where it’s at and maybe do a clean cancellation would be useful.

    #37874
    Brendan
    Keymaster

    Hi Rocky,

    I have a script here which continues execution after the results of the prompter are determined. Perhaps this will help you with what you want to do:

    var second_prompt;
    
    var output2 = function printOut2() {
    	console.log('second prompt: ' + second_prompt);
    }
    
    var output = function printOut(continueClicked) {
    	console.log(username + ", " + password + ", " + email_address + ", " + other_field + ", " + genre);
    		
    	if (continueClicked == true) {
    		let prompter2 = Prompter.new();
    		prompter2.addParameter('Did it work?: ', 'second_prompt')
    		.show('A second prompt', output2);
    	}
    	
    }
    
    var username;
    var password;
    var email_address;
    var other_field;
    var genre;
    var genres = ['Action & Adventure', 'Comedy', 'Drama', 'Horror', 'Science Fiction'];
    
    let prompter = Prompter.new();
    prompter.addParameter('Username: ', 'username')
    .addParameter('Password: ', 'password', 'secure')
    .addParameter('Email Address: ', 'email_address')
    .addParameter('Other: ', 'other_field')
    .addParameter('Genre: ', 'genre', 'popup', genres)
    .show('Enter a Username and Password and Stuff', output);
    

    Basically when the first prompter is run, the output of that is the execution of the output function which creates another prompter. Then that prompter is displayed. And the output of that is output2. So that’s how you can chain things together using the prompter.

    #37860
    Daniel Leu
    Participant

    I hope that one day I can use the Prompter for scanning items. Then things could be automated with a script.

    Cheers, Daniel

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

    #37856
    Sam Moffatt
    Participant

    I’m not sure you can fully do what you need with a script right now, the scripting interface doesn’t have a way of scanning anything.

    That said, what you can do is use the barcode scanner the search feature has to look up the record and if you had a checkmark for registration you could add a field script to watch that checkmark field and do what ever business process you need.

    #37849
    Brendan
    Keymaster

    @George, on the iOS version in the Script Editor, there’s a button on the toolbar just above the keyboard that kind of looks like a vertical set of boxes. Those are to represent fields. When you tap on that, Tap Forms will display the list of fields with a function selector for getting the field value or the field ID. When you tap on the field, Tap Forms will insert the variable into your source code, thus giving you the field ID or the value from the record and field that you’re looking for.

Viewing 15 results - 2,266 through 2,280 (of 3,011 total)