« MBS FileMaker Plugin,… | Home | FileMaker and Xojo Me… »

Passing parameters via dictionary functions


In recent plugin version we got new dictionary functions. Those can be used to quickly lookup some value for a key value. As the plugin preserves the original data type (e.g. containers), you can really use it to store anything very well. For example if you reference in your app some ID with a name, you can load all those values in a dictionary. New functions in version 5.1 will allow to fill it with SQL command easily.

 

For now we want to show you how to use it for parameter passing to scripts. FileMaker allows you to pass one script parameter and our idea is to pass the dictionary reference number as parameter instead of values. So in calling script we call Dictionary.Create to create a new dictionary. Than we fill in a few parameters with the Dictionary.SetValueForKey function. Finally we can pass our variable to the target script with the reference number.

 

#Create new Dictionary

Set Variable [$param; Value:MBS( "Dictionary.Create" )]

#Fill in parameters

Set Variable [$r; Value:MBS( "Dictionary.SetValueForKey"; $param; "text"; Test Table::TextField )]

Set Variable [$r; Value:MBS( "Dictionary.SetValueForKey"; $param; "number"; Test Table::NumberField)]

#Call script and pass ID

Perform Script [“Other Script”; Parameter: $param]

 

For the called script we have code like below. We first query the script parameter into local variable. Than we query all the values and put them in variables in the new script. Finally we have to free the dictionary.

 

#get dictionary reference number

#

Set Variable [$param; Value: Get(ScriptParameter) ]

# get some values back in variables

#

Set Variable [$text; Value: MBS( "Dictionary.ValueForKey"; $param; "text" ) ]

Set Variable [$number; Value: MBS( "Dictionary.ValueForKey"; $param; "number" ) ]

#

# and free memory

#

Set Variable [$r; Value: MBS("Dictionary.Release"; $param)]

 

As you see this needs some more work in the scripts. But we can make it easier. The calling script can use the function Dictionary.SetVariables (new in 5.1). This function uses the keys and values in dictionary for the variables. So if there is a key named "Company", we create a variable called $Company and fill the value. So you automatically get the variable names. Also the Dictionary.Create function now takes key/value pairs, to easily fill a dictionary in a script. See the following script:

 

Set Variable [ $param; Value: MBS( "Dictionary.Create"; "text"; Test Table::TextField; "number"; Test Table::NumberField) ] 

Perform Script [ “Script Called Copie” ; Parameter : $param ]

 

We create a dictionary with passing in variables as name and value. Than we pass the dictionary as parameter. The called script looks like this:

 

Set Variable [ $r; Value: MBS("Dictionary.SetVariables"; Get(ScriptParameter); 1) ] 

 

We get back those variables and passed them all in two lines from one script to other script. No more conversion to text or storing in global fields, even for containers. Try it! You'll love it.

17 03 15 - 20:33
two comments

I am not quite sure waht exactly this is for, could you give us a more detailed example?
Markus M. - 19 03 15 - 22:06

FileMaker can only pass one parameter for script calls. The solution about using Dictionary.Create and Dictionary.SetVariables provides a way to pass any number of variables and preserve their data type.
Christian Schmitz (URL) - 19 03 15 - 22:50


  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.