I’ve changed things for the next update with respect to editing scripts. No matter where you edit a script from in the next update, Tap Forms will go full screen for the editor. So there will be no chance of accidentally switching records and losing your script contents.
It’s best to declare variables within a function declaration.
function runPrompter() {
var upc_lookup_id = 'fld-8b5f99cd185044f8a0b35204db4c86ac';
record.getFieldValue(upc_lookup_id);
var callbackFunction = function() {
console.log(value_1);
};
var value_1;
let prompter = Prompter.new();
prompter.addParameter('Label 1').show('Message prompt', callbackFunction);
record.setFieldValue(upc_lookup_id, false);
document.saveAllChanges();
}
runPrompter();
That should work.
But it may be that you’ve found a bug that’s not clearing out the JSContext when you run the script the second time.
Also probably that I haven’t tested the prompter within a Script Field. I’ve only ever used it within a Form Script.
What is the recommendation in relation to declaration of variables in scripts?
I have a test/demo field script which is executed every time a check mark is changed.
The problem I have is when this is run for the 2nd and subsequent times I get an error since the variable is already declared (see error on screenshot attached).
var upc_lookup_id = 'fld-8b5f99cd185044f8a0b35204db4c86ac';
record.getFieldValue(upc_lookup_id);
var callbackFunction = function() {
console.log(value_1);
};
var value_1;
let prompter = Prompter.new();
prompter.addParameter('Label 1')
.show('Message prompt', callbackFunction);
record.setFieldValue(upc_lookup_id, false);
document.saveAllChanges();
It’s entirely possible I’m doing something daft since I’m new to javascript!
Attachments:
You must be
logged in to view attached files.
Fixed it, I was using a form script not a field script (assume it has to be the latter?).
Also I didn’t have this line in the script which I think is needed?
record.getFieldValue(upc_lookup_id);
Thanks
Just noticed a minor issue I think. If I’m editing a script and don’t save it then change the view on the left hand navigation then there’s no warning and my changes are lost. However if I navigate away using the right hand pane then I do get a warning.
Example in image (green gives warning, red does not).
Attachments:
You must be
logged in to view attached files.
Ah that’s an excellent idea. I tried it and it’s not working though, no-doubt an issue with me.
I have a Form Script with a reference to the check mark field in it:
var upc_lookup_id = ‘fld-8b5f99cd185044f8a0b35204db4c86ac’;
Which I assumed was sufficient to trigger the script when that field is updated?
Assume I’m missing something :-)
Well, with a Link to Form field, there’s no way in a Calculation field to reference an individual child record. So the only way to do it is to use JavaScript.
Going the other way was just a suggestion.
Well, you could simulate a button by adding a Checkmark field to your form and then reference that Checkmark field in your script. When you tap the Checkmark field, the script will run.
Brendan,
Thank you for the reply.
The script example, unfortunately, is beyond me (having no knowledge of JavaScript) at present.
I am not sure that I understand, fully, the following:
“then you could add a Calculation field to your Passports form that references the Client Contact data. In that situation because it’s as One-to-Many relationship, the inverse of that is a Many-to-One and you can reference individual fields from the one Client Contact record from within the Passport records.”
These seems to be suggesting the reverse what I am seeking.
I am not seeking to reference individual fields from the Client Contact record, but rather, the reverse, some fields from one of the records in the Passport form.
As I am new to Tap Forms I suspect I am missing something – further help would be greatly appreciated.
Any plans to add this to iOS versions, or if not layouts at least a simple button option in place of a field to trigger a given script. I think that’d be a great enhancement.
Cheers Ian
Oh yes. That’s right. Sorry about that. Custom layouts are only available on macOS and that’s why there’s no button function in the iOS version. You have to use the Run Script menu to activate a Form Script on iOS.
You’ll have to use a Script Field for this because the Calculation field cannot reference specific sub-records of a Link to Form field.
var passport_field_id = 'fld-....';
var passportRecords = record.getFieldValue(passport_field_id);
if (passportRecords.length > 0) {
var firstPassportRecord = passportRecords[0];
var number_field_id = 'fld....';
var number = firstPassportRecord.getFieldValue(number_field_id);
// and do whatever you want with the values/
}
Hope that makes sense.
But what you could do maybe instead of trying to extract the passport information on the Client Contact form into a Calculation field, you could go the other way around and if you’re using a One-to-Many Link Type from Client Contact to Passports, then you could add a Calculation field to your Passports form that references the Client Contact data. In that situation because it’s as One-to-Many relationship, the inverse of that is a Many-to-One and you can reference individual fields from the one Client Contact record from within the Passport records. You’ll notice that if you double-click on the inverse field of a One-to-Many relationship in the Formula Editor, you’ll get something like Client Contact::First Name instead of one of the aggregate math functions.
Thanks,
Brendan
Hi Ian,
On a custom layout you can add a button which you can click on to trigger a Form Script.
Click the custom layout, then the Layout button. At the top-right of the Layout Inspector panel you’ll see a “button” button. Click on it, then drag out a rectangle on your custom layout. Now on the Layout inspector panel you can set the Form Script to trigger when you click the button.
Hope that helps!
Brendan
Check out the Scripts page of the v5.3 manual. It gives a sample of the Prompter() function which seems to be what you are looking for.
Ron
Is there a way to use the share/send-to option on iOS Safari to pass information to Tap Forms? What I’m thinking is some sort of bookmark manager functionality so I’d want to pass the URL and title into a predetermined database. Alternatively would this be possible via a Safari bookmark with some Javascript in it, like I’ve seen for other bookmarklet functionality in the past?