From Dwayne Wright PMP
Certified FileMaker Developer
Please Note: If you are viewing this page in a news feeder, the images may get munged up a bit. For the best experience, please visit the journal directly by clicking (here).
The Perform Script script step is used to execute another script, often called a subscript. You can specify to run any of the scripts in the current database file or a script in another FileMaker file (including files on the network). It’s even possible to have a script call multiple other subscripts, that even have subscripts of their own. I've noticed this script step used in 4 major ways.
One is to call a script in another database to do something and stay in that other file.
Another is to call upon a script in another file and return the results to the original script. Now I have to say this isn’t as common as it used to be because there is no real need to do that anymore (at least in most situations). Using File References, you can do all the above without leaving your starting file or calling upon a subscript. This was not the case prior to FileMaker 7, so you may come across this script technique in newly converted FileMaker 6 solutions. It is a good idea to consolidate your scripts as much as possible and this is a great example of a place in which to do so.
Sorry about going off topic there, another common use of perform script is to create specific scripts for memory related script steps such as Page Setup or Sort Orders. These scripts can be called upon as subscripts by multiple scripts. Once again, you may come across this in newly converted FileMaker 6 solutions and it is no longer needed in FileMaker 7 and above.
Another common use is to take one big script and break it down into smaller subscripts. Sub-scripts can be easier for for minor modifications, sharing sets of scripts steps to other scripts and troubleshooting.
There is a "Perform subscripts" option that can be selected or deselected. When it is selected (which is the default), it will execute any Perform Script steps that are in that secondary script. This gives you the ability to have one script in charge of many subscripts, which in turn may have subscripts of their own.
HALT SCRIPT STEP VS EXIT SCRIPT STEP
The Halt script step is a way out of a currently running script and any subscripts attached to it. This is the opposite of the Exit script step that only stops the current running script.Halt Script is usually used as a logical branch option. If the user chooses this or a set of tested conditions are true then .... get out of here... otherwise, do something else.
I’ve also seen this script step be used as a kill switch when developing a complex script. The developer can create a script with just the Halt script step and leave it as an option under the Scripts menu. Then if a script goes awry ( like when ScriptMaker is in an endless loop ), the developer can activate the kill switch script via the menu or via a keyboard shortcut. Much better that force quitting FileMaker or pulling the plug on the computer!
Be sure that in using the Halt or Exit script steps, you do not strand the user on an unfamiliar layout or leave them in the wrong layout mode. Always make sure the user is on the layout and in the mode (Browse or Find usually) they should be in before you Exit / Halt a script.
HOW ABOUT AN EXAMPLE?
In this example, you click a button to start a script that counts up to 10. After the countdown reaches 4, a subscript is called upon that starts to show the seasons of the year. After Summer, a dialog box comes up saying ...
“Choose Halt to end the current script completely. Choose Exit to exit the seasons displayed and resume the number countdown.” This script will run the Halt script step, if you choose Halt and this script will run the Exit script step if you choose Exit.
The execution of the Halt script step will stop the running script and any other scripts that called upon it. This is effectively stopping ScriptMaker from running.
Exit will stop the running script ( the seasons subscript) but not any other scripts that called upon it ( the count up to 10).
Recently, the Exit script step had a new option added to it called the Script Result. When you select this option, you are greeted with the calculation dialog box. The value (text, field reference or calculation) that you place into this calculation dialog will be used when the script step is executed to return that value into memory. Then it can be used later via the Get(ScriptResult) function.
An example file can be downloaded by clicking (here).
More info about the author and FileMaker in general, contact me at email@example.com.
© 2008 - Dwayne Wright - dwaynewright.com
The material on this document is offered AS IS. There is NO REPRESENTATION OR WARRANTY, expressed or implied, nor does any other contributor to this document. WARRANTIES OF MERCHANT ABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED. Consequential and incidental damages are expressly excluded. FileMaker Pro is the registered trademark of FileMaker Inc.