Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › bug: new field won’t trigger script
- This topic has 5 replies, 2 voices, and was last updated 1 year, 7 months ago by Paul Wirth.
-
AuthorPosts
-
April 8, 2023 at 12:28 PM #49302
Paul WirthParticipantI think this is probably a bug.
I was attempting to get changes in a field to trigger a field script, using a reference to
record.getFieldValue('fld-blablablabla')
in the script. The script would only trigger when the field referenced was one that had already existed in the form (in this case, a text field that I wasn’t using). If I created a new text field, referencing the new field’s ID would never cause the script to be triggered when that new field’s value was changed.In the end, I went through the trouble of creating a script to copy all data from the field that worked correctly as a trigger, to a new field, just so I could use old field properly as a script trigger.
April 9, 2023 at 2:17 AM #49307
BrendanKeymasterHi Paul,
Tap Forms will only run the script if the field already exists in the form. That’s normal behaviour.
Try quitting Tap Forms and launching it again to see if script triggering works properly when you change a value in the referenced field.
April 9, 2023 at 11:04 PM #49311
Paul WirthParticipantHi Brendan,
Sorry, I didn’t explain well.
Plan A — When I:
– added a text field to the form
– referenced that field in the script (record.getFieldValue...
)
– changed the value of that fieldThe script didn’t trigger, including after restarting Tap Forms. I repeated this multiple times with new text fields
Plan B — When I:
– referenced a text field that had been there before introducing this script
– changed the value of that fieldThe script did trigger, consistently.
The plot thickens, though: Since I’ve returned to Tap Forms, Plan B also doesn’t work. The script no longer triggers when the text field is altered.
Here’s a basic script that repeats my issues:
function changeTargetOnTrigger() {
Utils.alertWithMessage('success!','the script was triggered');
const triggerFieldValue = record.getFieldValue('fld-d5bbf5db0052462e8e138d1636718d64');
const targetId = 'fld-a6c94d8bb94e4ee0a1287a046280a6d1';
record.setFieldValue(targetId, triggerFieldValue);
form.saveAllChanges();
}
changeTargetOnTrigger();I’m attaching a minimal document that includes the script and relevant fields (Basically just a form with three fields: “Target”, “Trigger”, and “Script”.
When running the script manually, the value of the field “Trigger” is applied to the field “Target”. But when changing the value of the field “Trigger”, the script doesn’t run. Maybe I’m missing something obvious!
- This reply was modified 1 year, 7 months ago by Paul Wirth.
- This reply was modified 1 year, 7 months ago by Paul Wirth.
April 9, 2023 at 11:43 PM #49315
Paul WirthParticipantToo late to edit my previous post. I believe I found the issue:
I’ve been editing my scripts in VSCode, and when a javascript line is beyond a certain length, either it (or the Prettier plugin) makes line breaks like this:
const triggerFieldValue = record.getFieldValue( 'fld-07c030d45e8642158be624403154874e' );
When I edit the line in Tap Forms so that it reads all in one line, everything works.
I’m guessing that Tap Forms is looking for a contiguous string like
record.getFieldValue('fld-blablabla
to set up the script trigger, and gets thrown off by line breaks.Not a huge deal, but perhaps that would be helpful to account for, for those of us who like to edit outside of Tap Forms?
Edit: in the meantime, the Prettier plugin .prettierrc.js can be made to stop breaking long lines with:
module.exports = { printWidth: 999, // Tap Forms script trigger expects <code>record.getFieldValue('fld-...)</code> to be all on a single line };
—
Additional request: could you possibly account for variables in place of the actual field ID string, and still trigger a script? e.g.,:
const triggerFieldId = 'fld-07c030d45e8642158be624403154874e'; const triggerFieldValue = record.getFieldValue(triggerFieldId);
- This reply was modified 1 year, 7 months ago by Paul Wirth.
- This reply was modified 1 year, 7 months ago by Paul Wirth.
- This reply was modified 1 year, 7 months ago by Paul Wirth.
- This reply was modified 1 year, 7 months ago by Paul Wirth.
- This reply was modified 1 year, 7 months ago by Paul Wirth.
April 10, 2023 at 1:30 AM #49321
BrendanKeymasterI’m glad you found the solution. I guess I should be a bit more thorough about scanning for the field ID, including linebreaks.
Tap Forms will already account for variables.
It also only looks for single quotes around the
'fld-....'
value.April 10, 2023 at 7:39 AM #49324
Paul WirthParticipantThanks, Brendan! Re variables, I had thought it wasn’t accounting for them, but you’re right, it does. I must have missed it when I hadn’t really understood what was causing the issue I was having.
-
AuthorPosts
You must be logged in to reply to this topic.