FileMaker: Passing Multiple Script Parameters

This is going to be a post laying the foundation for more to come.

In FileMaker there is no native way to send multiple script parameter. All you have is a single line that you can type whatever you want into.That works well enough when you want to pass a single parameter but what if you want to pass multiple parameter to the script?

Different Methods

Word Count

Rather than just entering a single word in the script parameter box you can enter a string of words, kind of like a nonsensical sentence. You can then use the LeftWords(), RightWords(), and MiddleWords() functions to parse out any individual word (parameter) from the entire string.

There is 1 major downside to using a word count system and that is that the number of words for each parameter must be constant for every use case. For example, let's say that I need to pass a name pulled from a field as a parameter. If I design the script to be expecting a first name and a last name, what happens when the name passed has a first, last, and middle name? The middle name is another word which will throw off the word count being used. Or, what happens if one of those parameters is NULL and has no words to be counted.

Value Count

The value count method uses the same principle as the word count method but rather than counting words you are counting carriage returned values. The list of values can be constructed using the List() function or be separating the values in the string with a pilcrow ("¶"). Values can then be retrieved using the GetValue() function.

This solves the major problem with the word count method in that each value can contain as many or as few words as necessary. You are counting values and not words so multiple word parameters are fine as are NULL parameters. That is not to say that the value count is without problems. If you are pulling data directly from field in your database there is always the chance that a user has accidentally added a carriage return to the end of field. This carriage return in the data would be evaluated as an additional parameter by the calc engine.

Another problem, and my big concern, is that you need to remember what value number corresponds to which parameter for which script. You need to recall that, script A is looking for the Primary Key as the 1st value while the Last Name is the 4th value. Script D, however, may only need 2 parameter so the Primary Key is 1st and the Last Name is 2nd.

Delimiting Characters

You could pass multiple parameters by using some rare or unique character as a delimiter between them. In the past I have used the pipe ("|"), the carrot ("^"), the backslash ("\"), and even greek symbols ("∂" and "Ω"). I then used a combination of the Position() and Middle() functions to extract the required text.

This solves the multiple word problem and the extra carriage return problem but it doesn't solve the "which value number is which parameter" problem. Also, there is always a chance that a user may, accidentally or otherwise, use your delimiter symbol in actual text.


The final, and my preferred, method is to use a dictionary to create a set of name/value pairs. This is a much more complex but much more robust way to do things.

Name/Value pairs are a method in which a value is paired with name that describes or identifies that value, thus Name/Value pairs. The syntax that is used to make the pairing is usually referred to as a dictionary because you have to create a syntax, or language, to encode and decode the data. The dictionary that you use is completely up to you as a developer. You can use steal one from someone else or create one on your own.

The most common example of name/value pairs is XML. In XML if you wanted to pass a room location as a parameter it may look like this:

<room>Indigo Ballroom B</room>

In this example the data, or value, that we are passing in "Indigo Ballroom B" and we have given it the arbitrary name of "room". We could have multiple parameter encoded in a similar way and as long as the name for each is unique it is easy to extract any parameter.

This solves all of the problems from the previous methods. It doesn't matter how many words are in each paramter or if the word count varies. It doesn't matter if there are extraneous carriage returns in the data. It also doesn't matter what order you pass the parameters in as long as you know what name you used to pass the value.

The dictionary that I use came directly from Six.Fried.Rice's Jesse Antunes and can be found here:

Using the example from above, the parameter looks like this once it is passed "<:room:=Indigo Ballroom B:>". You have closing and opening character strings ("<:" and ":>") and a simple character string separating the name from the value (":="). The custom functions that Jesse provides also take care of escaping any characters that could cause trouble (for example, if your data contained colons, equal signs, etc.).

When you want to pass a parameter you use the custom function PassParameter(), i.e. PassParameter( "room" ; "Indigo Ballroom B" )

There are only 2 potential concerns with using this method. First, you have to have FileMaker Pro Advanced so that you can make the custom functions. Second, it is a bit more to type to encode the parameters but I gladly make that sacrifice for the ease of extraction.

When I want to extract a parameter all I have to do is use the GetParameter() function, i.e. GetParameter( "room" ). It doesn't matter how many words are in the room, how many carriage returns the room has in it, or where that room is located in all of Get( ScriptParameter ). It will find it, extract it, and decode it back to what it was when it was passed.

Use Cases

The next stop is showing how you can use the dictionary method to do more than just script parameters.