Perform Script and script parameter example
Perform Script performs a script that is defined in the current file or in another FileMaker Pro file.
Optional script parameters can pass text into a script. For example, you can use a script parameter to store the active record number when a script is initiated, making it easy to return to that record at the end of the script. Or you can call the same script from different buttons on the same layout, and easily determine which button called the script by using a different script parameter for each button.
When you specify a parameter, you can access it within a script or pass it to other scripts using the Get(ScriptParameter) function.
Complex parameters, such as a list of names or other values, can also be used. Complex parameters that are separated by carriage returns can be parsed using the LeftValues function, MiddleValues function, and RightValues function. These functions return the beginning, middle, and ending values from lists that are separated by carriage returns. Complex parameters separated by other characters can be parsed as text using functions such as Left function, Middle function, and Right function.
A script parameter exists only for the duration of the script. Script parameters are reset each time a script is performed. If you want a script parameter to persist while a file is open, you can use a global variable as the script parameter.
A script parameter can be used (but not modified) within a script and can be passed along to sub-scripts by using the Get(ScriptParameter) function as the parameter for the sub-script. You can also specify different parameters each time the sub-script is called using Perform Script. Changing the parameters passed to a sub-script does not modify the value of the parameters returned from Get(ScriptParameter) in the parent script.
Example 1
#This example uses the script parameter to set the title of the report
Go to Layout ["Detailed Report"]
Perform Script ["Sort by Date"; Parameter: "Month End Report"]
Set Field [Sales::Report Title; Get( ScriptParameter )]
Perform Script ["Print in Landscape"]
Example 2
#This example passes a script parameter from one script to another.
#Assume this script was called with the parameter string value "Classes::Introduction to French"
Go to Layout [Get( ScriptParameter )]
Perform Script ["Monthly attendance report"; Parameter: "Month of "
& Month (Get( CurrentDate ))]
Sort Records [Restore; No dialog]
Print Setup [Restore; No dialog]
Print [Restore; No dialog]
#In this next step, the value returned for the ScriptParameter is
still the original "Introduction To French", which will be the
parameter used in the sub-script "Monthly grade report"
#The previous Perform Script did not change the value for the
parameter inside this main script
Perform Script ["Monthly grade report"; Parameter: Get(ScriptParameter)]
Sort Records [Restore; No dialog]
Print Setup [Restore; No dialog]
Print [Restore; No dialog]