Function Scripting [ learn ]
by Michael Gaslowitz
The method I use to pass and retrieve parameters in almost all of my scripts is something I learned from Matt Petrowsky’s instructional video at FileMaker Magazine called Function Scripting. It is not for beginners, but it is one of the more powerful and dynamic things you can learn to do with FileMaker.
Function Scripting requires three custom functions to do the heavy lifting; one by Alexander Zueiv, and two by Mikhail Edoshin.
A copy of FileMaker Pro Advance will be needed to view the custom functions. If you do not have a copy of FileMaker Pro Advanced, you will still be able to use the sample file.
Name your scripts [ like; this ]
To use this method you need to format the names of your scripts with the parameters the script will use:
Example Script [ expected; (this|or|that) {; optional } ]
Notice how it looks like a function? This is why it is called Function Scripting! How about some real-world examples:
Dialog [ title ; message ] // A script that takes two parameters: title and message Create [ name ; user|admin ] // A script that uses an "or" Record [ ID ; add|delete ; action ] // A script that uses an "or" and optional third parameter
Spaces are not important, but the brackets, semicolons, and pipes are. Your scripts will not work if you omit them.
Supply parameters
When passing parameters into a script, format them using the custom function param.set[ ]:
param.set( "expected" ; "value1" ) & param.set( "this|or|that" ; "value2" ) & param.set( "optional" ; "value3" )
I have formatted the parameters for the dialog script. Try to do the other two scripts yourself, or consult the sample file:
param.set( "title" ; "Alert") & param.set( "message" ; "This is an alert!" )
Now the magic
The custom function param.assign[ ] does the rest of the work. Use it at the beginning of the script, and it will do two things:
- It will first check to see if you supplied and properly formatted all of the script’s parameters, and if you did,
- it will then assign each parameter to a $local variable to use throughout the script.
If [param.assign] //Do something here Else //Parameters not assigned End If
Our script:
Dialog [ title ; message ]
Receives parameters:
param.set ( "title" ; "Alert") & param.set ( "message" ; "This is an alert!" )
And performs the following steps:
If [ param.assign ] // We now have variables to use throughout the script: // $title = "Alert" // $message = "This is an alert." Show Custom Dialog [ $title; $message ] Else // Missing or improperly formatted parameters Show Custom Dialog [ "Missing Parameters"; "Parameters not assigned."] End If
Download the sample file
I have included examples in the the sample file that you how to use the (this|or|that) parameter, and how to pass retrieve multiple parameters using the param.get( ) custom function.
May 29, 2008 • Custom Function, FileMaker, Scripting • Comments Off




















