Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Script on a Field
Tagged: Field Script
- This topic has 7 replies, 2 voices, and was last updated 2 years, 8 months ago by Daniel Leu.
-
AuthorPosts
-
March 15, 2022 at 5:52 PM #46983
Bernie McGuireParticipantHello All. Im new to Tap Forms but am an experienced software developer. I can not get a script attached to a fied to execute. I put the same script at the form level and it executes perfectly when I click ‘run script’ Im using iOS on iPhone 13 latest OS and V5 of Tap Forms
Simple Form
Field1 Text
Fiedl2 number
Total1 -Script field
Total2 Number (to hold the calculated total)I have the script attached to Total1.
Basically gets the Field ID of Field2 (using the getID from the field list dialogue), does a var total = form.getTotalAllFields(field2_id) ,
does, setFieldValud(total2_id,total), I have both form.saveAllChanges and document.saveAllChanges. I also return total from the function.
As I mention this script runs perfect from the form object.I know there is a simple answer but I can not figure it out. I have tried all the suggestions I have found but none are working for me.
Thanks for any help.March 15, 2022 at 8:00 PM #46984
Daniel LeuParticipantIt looks like your script is not triggered. This might be due to using
field.getId()
. I would try this: in the script editor, click on the icon between ‘fx’ and ‘ABC’, selectfield_id
, then click on your variable. This will provide you with the id definition that Tf uses to determine when to trigger a field script.Hope this helps!
March 15, 2022 at 9:09 PM #46985
Bernie McGuireParticipantHello, Thanks for the reply. Yes, that is the field_id I am using. I didn’t explain it too well but yes, I have the long unique identifer as the field id in a var created like you suggest.
Anything else I can try ?
March 15, 2022 at 9:26 PM #46986
Daniel LeuParticipantMaybe sharing your script?
March 15, 2022 at 9:33 PM #46987
Bernie McGuireParticipantMy script.
function Total1() {var field2_id = ‘fld-1e5045dd497f4359a0a98b5bbc010059’;
var total = form.getTotalOfField(field2_id);
var total2_id = ‘fld-737e46579abc42b0a42dafb6f06b0bf8’;
record.setFieldValue(total2_id,total);;
form.saveAllChanges();
document.saveAllChanges();
return total;}
Total1();
March 15, 2022 at 11:07 PM #46988
Daniel LeuParticipantI added a dummy
var number = record.getFieldValue(field2_id);
and now the field script gets executed upon a value change.March 16, 2022 at 9:48 AM #46990
Bernie McGuireParticipantPerfect!! Works great. I’m sure I don’t need both the saveAllChanges. I’ll remove one. Thanks again
March 16, 2022 at 1:52 PM #46991
Daniel LeuParticipantGreat! Yes, one
saveAllChanges()
is sufficient. It doesn’t matter which one you use. -
AuthorPosts
You must be logged in to reply to this topic.