Dealing with FileMaker script parameters (Scripts as Functions)

One of my naming standards has been with script names. Through many versions of FileMaker Pro I have tried to keep my script names clear and concise. This has worked well for me. When FileMaker introduced script parameters in version 7 that was a huge improvement. With script parameters came the function Get(ScriptParameter). And we learned to pass multiple parameters in a return delimited list. So scripts with multiple parameters would have several instances of this for each value:

GetValue ( Get (ScriptParameter) ; $x )

What quickly became an annoyance for me was that when I called a script from a button I couldn’t always remember what parameters the script was expecting. I had to stop what I was doing, open the specific script in Manage Scripts and make note of the required parameters. So I started putting the parameters in the script name, much like functions.

Navigate ( layoutName ; objectName )

Now when I called a script I knew what was expected without opening and looking through the script. And when I was writing the script I could always reference the name for which parameter was which.

GetValue ( Get (ScriptParameter) ; 1 )  in the above example is the layout name

GetValue ( Get (ScriptParameter) ; 2 )    would be the object name

But when writing a long script that might call a parameter more than once or had several parameters this got tedious. I thought, wouldn’t this be easier if I could just reference the parameter names as they appear in the script name. This would also make it easier to read the script or debug it later.

At the beginning of each script I thought of listing out the parameters and moving them to variables.

SetVariable ( $layoutName ; GetValue ( Get (ScriptParameter) ; 1 ) )

SetVariable ( $objectName ; GetValue ( Get (ScriptParameter) ; 2 ) )

Now I can just use $layoutName anywhere that I need it in the script itself.

But I realized that I was typing out information that I already had in the script name. And I didn’t like the idea of extra data in the parameters. I just want to send the parameters with RETURN delimiters. Shouldn’t a custom function be able to handle this?

Which brought me to the CVFP custom function. This custom function creates the variables automatically by referencing the script name. Now at the start of any script that accepts parameters I add the script step

SetVariable( $result ; CVFP ( “” ; “” ; “” ) )

With this all of my variables are generated automatically making the script easier to write and read. CVFP

 

 

You can imagine in a script with dozens or a hundred or more lines how much easier the script would be to read using variable names rather than calculations with

Passing the script parameters might look like this:

Parameters

 

where a layout is named “Client Detail Layout” and there is a named object “field.FirstName

You can find our CG_CVFP custom function on Brian Dunning’s website.

Leave a Comment

Your email address will not be published. Required fields are marked *