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,236 through 2,250 (of 2,986 total)
  • Author
    Search Results
  • #37961
    Sam Moffatt
    Participant

    If you’re using a form script, then you’ll want to use something like Utils.alertWithMessage to display it if you aren’t sending it somewhere else, e.g.:

    Utils.alertWithMessage('Calculation Result', checked / records.length * 100);
    

    Or to put that as the full script using your field ID:

    var check_mark_id = 'fld-4cbc05636709431a8305cfb7739a9bc5';
    var records = form.getRecords();
    var checked = 0;
    for (record of records)
    {
    	checked += record.getFieldValue(check_mark_id);
    }
    
    let percentage = checked / records.length * 100;
    Utils.alertWithMessage('Calculation Result', percentage);
    percentage;
    

    You can paste that into the script editor without having to define a function and it will work. The default Tap Forms script sample includes a function because otherwise some of the flow control keywords like return don’t behave normally.

    Also in the script editor when you run it, it should give you the output on the left or any errors n on the right.

    Attachments:
    You must be logged in to view attached files.
    #37960
    Sam Moffatt
    Participant

    I used a file attachment field to get the file browser to prompt and select the file. Once you’ve done that, I think Tap Forms should have access to the file.

    So create a form somewhere with a file attachment field, add to it your AppleScript app and then you should be able to execute it.

    Also getting access to the latest beta should help you as well.

    #37955
    Roy McKee
    Participant

    Hi Sam
    Thanks for the script. I have created it as you say, replacing the check-mark-id and field ref, thus:

    function Script_Google_No_1_S() {

    // My Code
    var Google_No_1_id = ‘fld-4cbc05636709431a8305cfb7739a9bc5’;
    var records = form.getRecords();
    var checked = 0;
    for (record of records)
    {
    checked += record.getFieldValue(Google_No_1_id);
    }

    checked / records.length * 100

    Script_Google_No_1_S();

    but nothing happens. Have I done something wrong?

    #37954
    Martin Inchley
    Participant

    @Sam I re-created your scenario with my own file names in place. The AppleScript triggers <Land AppleScript> fine. However, when I called the Run AppleScript script to start the process, I got an error from the Mac: ‘The application “Tap Forms Mac 5” does not have permission to open “(null).” ‘ Do you know where the permissions for that are set?

    #37950
    Sam Moffatt
    Participant

    I’d suggest looking at a tool like Automatic that will automatically record your trips for you. I bought a gen 2 model from them and it is generally gooda about recording trips and uploading them. Then you can export the CSV from the Automatic Dashboard and import that into Tap Forms as a set of records. Here’s a custom layout with a sample record from Automatic:

    I went with an approach of splitting the start and end with their fields aligned at the top and the location fields immediately below it. This two panel style also naturally helps compact some of the other details. As you can see it sometimes doesn’t get the location fully detailed but the geo point generally gets it. In theory you can hook up API access to Automatic but I find you can export the data when you care about it. The JSON format has more data in it than what they export as CSV though but you can see it likely has what you need.

    I’ve personally moved onto another OBD adapter that gives me a lot more low level detail but the Automatic adapter worked reasonably well for me for three years I was using it. They deprecated that Adapter and I chose to move on. The newer adapter gives me second level precision which is useful but creates really large log files. If you want a mostly turn key solution, Automatic is the way to go.

    I’ve also attached my refueling log entries script. When I refuel my car, I write down the details from the car’s computer (trip distance, odo, estimated range (before and after refueling), MPG/MPH and drive time. Comes with a layout I use for side by side data entry. I use VueScan to do my initial import of the receipt which creates a new Tap Forms record I can transcribe the details from later.

    Attachments:
    You must be logged in to view attached files.
    #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').

Viewing 15 results - 2,236 through 2,250 (of 2,986 total)