Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Feature or Fluke?
- This topic has 4 replies, 2 voices, and was last updated 2 years, 4 months ago by Bernie McGuire.
-
AuthorPosts
-
June 22, 2022 at 10:07 AM #47524
Bernie McGuireParticipantI have a situation which I don’t know if it works because of TF design or just happens to work now and maybe will not in the future.
I have a ‘Result’ field , on a ‘Entry Form’ , that can have 17 different values. I use a pick list to have the operator populate the field.
On the ‘Totals’ form I want to show a count (and percentage) of each result value. So I have a script that will loop througe the records on the linked ‘Entry Forms’ and count the ‘Results’. This script function takes an input parmater containe the ‘Result’ value I want a total for and return the appropiate value.
So rather than duplicating the script in 17 different total fields I placed the script (named CountResults) in the FIRST field on the Totals form, and then for the other 16 i just execute ‘CountResult(‘xxx’)
This only seems to work if the script (CountResults) is in the first field on the totals form.
So, is this a feature I can rely on now and in future releases, or not?
(I understand the risks if the script field changed location, etc.Thansk
BernieJune 22, 2022 at 6:18 PM #47528
Daniel LeuParticipantI usually create a form named
Scripts
and place all javascript functions in form scripts (eg, Common). I try to organize them logically so I can easily reuse them. Then in the field script, I usedocument.getFormNamed('Scripts').runScriptNamed('Common');
to load one (or several) of these form scripts. Later I can execute whatever function I need.- This reply was modified 2 years, 4 months ago by Daniel Leu.
June 23, 2022 at 11:27 AM #47533
Bernie McGuireParticipantDaniel, This is a great idea. A question , when you say “Then in the field script, I use document.getFormNamed ..” You put this in the first field script on the other forms so they can execute the functions in ‘Common’, correct?
Do you get this first field scrip to execute automatically (by watchin a field on the form) ? or does your user have to do ‘refresh’ to get things started? I am having a very hard time getting a script to run automatically, based on a field change, I have dried a dozen ways. I need to have the user hit ‘refresh’ How do you do it ?
Thanks for you help
BernieJune 23, 2022 at 3:54 PM #47547
Daniel LeuParticipantI use this whenever I need a function from my ‘script library’. I don’t care if the script is called several times. But I protect the content of these library scripts so they are not executed more than once. Here is the example of my Common script:
// Only define functions once and skip them when already called if (typeof commonScript === undefined){ var commonScript = 1; // here go your function definitions }
Obviously there is a performance penalty when you have many script fields that use this include and you do a refresh of *all* records.
But yeah, sometimes it is a challenge to get a field script trigger upon a field change… I run into this as well… I usually try to have all field defines at the top of the script:
var fldName = 'fld-xxx' ...
And then in the script I just use these defined variables or constants.
Hope this helps!
June 28, 2022 at 4:58 PM #47559
Bernie McGuireParticipantDaniel, Thanks again for the help. I am not on this full time so I apologize for the delay in reply. This has been very helpful. Thanks!
-
AuthorPosts
You must be logged in to reply to this topic.