Field scripts are executed when any of the other fields the script references change.
So if you have a script that references a Checkmark field, then when you click the Checkmark in the form, the script that references that field should execute.
Same on iOS or Mac.
But you can trigger all the scripts to run in all of the records by clicking the Refresh button at the bottom of the records list view. On iOS you can pull down on the records list view to trigger all the Calculation and Script fields to execute.
Form scripts run only when you manually trigger them.
I want to run some JavaScript when a check box is checked on a record (I have a field script that checks the value of the checkbox, if checked it runs the main logic and then unsets the check box).
I was wondering how often a field script is run?
- On every update
- Every time the record in viewed
- On import
Also, does this vary between iOS and MacOS?
Thanks
Martin
Thank you for all your help.
The solution I have gone with is to have a field script that updates the record (from the webscrape). I have also added a check mark to say when I want it to run.
The field script checks the value of the check mark and if set, it runs the web scrape, updates the fields and then unchecked the checkmark.
Thank you
Sure, you could update a record in a Field Script. An example of that might be selecting something from a Pick List that triggers a script to run and it updates a different field in that same record.
You could also have a Saved Search that fetches the records you want to update and run the script just on those records. You would use search.getRecords()
instead of form.getRecords()
. Or you can ask the form for a specific with a provided name. E.g. var search = form.getSearchNamed('Action & Adventure');
Then do search.getRecords();
.
Hi,
Thanks for all your help with the queries I’ve had regarding scripting on iOS.
I’ve found it quite hard to debug on iOS as I can’t see where the console.log() output goes. Is there somewhere I can view the console?
It works in on MacOS (but I rarely have access to my Mac so rely on iOS)
Thanks again,
Marrin
Actually the script does seem to be running, but a second call to alertWithMessage isn’t showing, nor is the final “success” dialog.
I will have to investigate further.
Yes that’s right. It’s good for showing the results of running a script. It’s displayed asynchronously after the script executes.
Good question about whether it is a form script or field script. It’s a form script (would updating a record in a field script make sense?)
I don’t want to loop through and find the record as I am scraping a website (for missing image data) and don’t want to run though all 1000 records and hit the website. On the Mac I was relying on the current record, I guess I can’t do that on iOS.
I will add an extra check box that I will set manually before running the script and then the script can search on that.
Thank you. I have tried:
Utils.alertWithMessage("almost done", record);
And it puts up a dialog box, but the script doesn’t continue after pressing OK.
Is it only intended to be used at the end of a script?
Hi Martin,
The promptForInput function was an old function that is no longer there for Mac or iOS. I inadvertently forgot to update the manual with the new Prompter() class API. I’ve fixed the documentation for that now. But I still have to implement that on the iOS version
The Utils.alertWithMessage('Script Run Complete!', 'Cool!!!!!');
function should work on iOS though. I just tested it and it does work.
Thanks!
Brendan
Hi Martin,
Is this a form script or a Script field?
If it’s a Script field, then record
should refer to the current record.
If it’s a form script, then you’ll need to find the record you want to update within the script by searching for the right record by looping through them.
I have a test script that updates a record on MacOS Tap Forms, but it doesn’t update the record on my iPad.
Here is an example:
var field_id = ‘fld-43e292a99a1646f1b5574954169ab319’;
record.setFieldValue(field_id, ‘Martin’);
document.saveAllChanges();
Could you please point me in the right direction to get this working on my iPad (works great on MacOS).
The database was created on the Mac and shared to the iPad, then synchronised with Nearby Sync.
Also, does the concept of current record exist in iPhone scripts?
Hi Kenneth,
Which version do you have? You can do this on the Mac version by clicking the location button on the field in the record and then changing the coordinates in the field there. Plus you can edit the name itself on the record details view.
I suspect you could do it with a script as well.
The structure of the Location field value is a dictionary that looks like this:
{
altitude = "2674953.657398775";
heading = "-0";
lat = "50.337885";
lon = "-115.853054";
pitch = 0;
title = "4992 Falcon Dr, East Kootenay F BC V0B 1L1, Canada";
}
Not all values are required. The heading, altitude, and pitch values are just for supporting the 3D map view on the Mac version.
So ya, if you can generate a dictionary of values like the above, you could probably use it with the record.setFieldValue(fld_id, value);
function.
Thanks!
Brendan
Hi Martin,
I haven’t written any code to enable access to the clipboard. I’m not sure that JavaScript directly allows that so I would have to write some Objective-C code that allows access to it.
Thanks,
Brendan
Location Field Editing
I use Tap Forms as a logging device to capture events that have date/time and location components. There is a problem with Apple Maps (and presumably with Google Maps as well) that it does not identify the correct address with the GPS coordinates. As an example, an event logged at my home places the address of my home over on the next block with a totally erroneous street address. Unless you have some secret mechanisms with Apple APIs to tweak this, I have found no other way. Locations are always wrong in any app that I use that captures location data.
So my question is about how to edit these erroneous addresses. Can you share what the internal structure of the Location field is. At a minimum there seems to be the text component that holds the found address. Then there are one or two fields to old the longitude and latitude as single data points, or as one data point.
Can these internal Location field structures be edited by either a calculation field or a script field? And if so, how.
Ideally, I would like to establish the coordinates of a GPS rectangle that surrounds my house at a reasonable distance. Then test the GPS coordinates populated in the Location Field. If these coordinates are within this pre-established rectangle, then reset the captured GPS coordinates to the one, and only, GPS coordinate for the center of my house. Then change the address portion of the field to the correct address of my house.
Is this possible within Tap Forms? Or does it involve exporting the database to Excel or some other tool and doing the edits there?
Thank you for your counsel.
Kenneth James