Brian Dunning's FileMaker Custom Functions

SetVarsUsingNVPs ( InNVPs )

Creates local variables using Name=Value Pairs

  Be the first to rate this function Log in to vote

Richard DeShong   Richard DeShong - Show more from this author
Logic Tools

  Sample input:
NVParse ( "Var1=That|Var2=These|Lines=Line1¶Line2¶Line3" )
  Sample output:
No output. For each "Name=Value" pair in the parameter, it creates a local($) script variable with the given "Name", and the specified "Value".

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

The parameter, InNVPs, is one or more Name=Value Pairs (NVP's).
If more than one NVP, then they are separated by the vertical-bar (|) or "pipe" character.
Values can have FM-returns (¶), but cannot have vertical-bars (|).

I mostly use this to pass one or more key values into scripts. When calling a script, I can create a "bar-delimited" name=value list right in the script parameter calc field. Then in the called script, one Set Variable() statement creates all of the local variables in the list.

Example: if I want to pass 2 key values to a script, it looks like this:
Perform Script ["MyScript"; Parameter:"Key1=1234|Key2=Regular"]

And in MyScript I use:
Set Variable [$set_vars; Value: SetVarsUsingNVPs( Get( ScriptParameter ) )
and it will create two variables:
$Key1 with a value of "1234"
$Key2 with a value of "Regular"

NOTES:
(1)The use of "[R]" to substitute for "¶" can be replaced with any unique value - this means something that you know will not be in your data.
(2) Do NOT put spaces before or after the equal sign in the Name=Value pairs.
(3) This is expecting FM data -- so does not handle or .
(4) The data values cannot have the pipe characters in them - no list within list.

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 22 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: