Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Issues with very basic Field Script Output
- This topic has 3 replies, 2 voices, and was last updated 4 years, 11 months ago by Wayne Powell.
-
AuthorPosts
-
January 1, 2020 at 10:20 AM #39050
Wayne PowellParticipant(I am moving this from another Forum as the question is more Script based.)
My knowledge of JavaScript is VERY rudimentary although I am generally familiar with object oriented programming and can pick things up quickly with working examples.
I first tried this without being in a function, and didn’t get an error, but then also do not get a result in the Script Field.
SO I changed the script to below and now get an odd error like it can no longer find the very same field record.
(If I “Paste” in from the snippet editor, I get the very same field id so that is not the error!?)
function calculation_result () { var length = record.getFieldValue('fld-0f39aaf844314fde8b5af7adb5d3bd5f'); var value_unit = record.getFieldValue('fld-616fa42329f347148fa7813db6a3289b'); var result_unit = record.getFieldValue('fld-3148ad66cbb14d5b875ee8b26429cdec'); var result = ""; if (result_unit == "inches") { if (value_unit == "feet") { result = length * 12; } else if (value_unit == "yard") { result = length * 36; } else if (value_unit == "cm") { result = length * 2.54; } else if (value_unit == "metre") { result = length * 0.0254; } else { result = length; } } if (result_unit == "feet") { if (value_unit == "inches") { result = length / 12; } else if (value_unit == "yard") { result = length / 3; } else if (value_unit == "cm") { result = length * 30.48; } else if (value_unit == "metre") { result = length * 0.3048; } else { result = length; } } if (result_unit == "yard") { if (value_unit == "inches") { result = length / 36; } else if (value_unit == "feet") { result = length / 3; } else if (value_unit == "cm") { result = length * 0.0109361; } else if (value_unit == "metre") { result = length * 1.09361; } else { result = length; } } if (result_unit == "cm") { if (value_unit == "inches") { result = length * 2.54; } else if (value_unit == "feet") { result = length * 30.48; } else if (value_unit == "yard") { result = length * 91.44; } else if (value_unit == "metre") { result = length * 100; } else { result = length; } } if (result_unit == "metre") { if (value_unit == "inches") { result = length / 39.37; } else if (value_unit == "feet") { result = length * 0.3048; } else if (value_unit == "cm") { result = length / 100; } else if (value_unit == "yard") { result = length * 0.9144; } else { result = length; } } return result; } calculation_result();
This gives me the error:
ReferenceError: Can’t find variable: record. Column:20, line:2
I must be missing something very simple about field declarations that I can’t see.
January 1, 2020 at 10:32 AM #39052
Wayne PowellParticipantThat error “Can’t find variable: record.” Occurs now whenever I make any Field Script field and then try to add a variable from the snippets.
I’ve tested very simple scripts (like
1+1+1
) and that works fine.
Not sure if it matters, but I am experimenting with basic scripts using my iPad (Generation 6).Frustrating as I can’t move even an “inch” forward with this and not certain why. Lol
January 1, 2020 at 12:30 PM #39053
Sam MoffattParticipantI created a new form with the three fields, created a new script field, pasted your script in, changed the field ID’s around and it worked out of the box for me. Tested on TF 5.3.9 (Build 955) from MAS.
The
Can't find variable: record
error I know happens with form scripts from time to time and if you’re working in the script editor I have seen it get disconnected from state though I’ve never been able to reproduce it consistently. The one I run into from time to time is thatform
isn’t a variable for my form script however closing the script editor and re-opening it seems to reconnect everything for me.If you’re still getting the hang of Javascript, Humble Bundle have a book bundle including “Javascript: The Good Parts” for their $1 tier. I came to JS a little earlier than the book, so I’ve never read it but I’ve had plenty of folk I trust who have read it that found it useful. It’s available as a part of the O’Reilly Classics bundle over at Humble Bundle. Humble do books in generally PDF, Mobi and ePub.
January 2, 2020 at 6:15 AM #39064
Wayne PowellParticipantBrilliant, thank you Sam! I totally forgot the IT Crowd Mantra = “Have you tried turning it off and on again?”
Closing Tap Forms and restarting it fixed the issue, the script works again! Now I just have to fix my calculation values.
-
AuthorPosts
You must be logged in to reply to this topic.