ISO FileMaker Magazine: FileMaker Video Tutorials, Templates, Help & More

Navigation

Video Browser

Scriptology Video Browser

Tools & Resources

Dynamic Variables

Posted by: aflgenx / Tuesday, June 26, 2007 – 8:10am

Hi Guys,

I recently had the need (or more likely the desire) to set global variables dynamically..

As most of you will know, Set variable allows you to specify a dynamic value and repetition, but not a dynamic name for your variable. This often leads you to store info in a delimited list within one repetition when you need to store multiple peices of information per one subject.

This will soon make your scripts become messy and the logic harder to follow

Hence two small custom functions:

Custom Function: SetGlobalVariable( name ; value ; repetition)
Evaluate("Let( $$" & name & "[" & repetition & "] = \"" & value & "\" ; \"\" )" )

Example Usage: SetGlobalVariable( "record_" & table::primaryKey ; table::aField ; 1 )

If your primaryKey field contained "991" and your aField field contained "Alex!!" -
This would be the equivalent of using the script step: Set Variable( $$record_991[1] ; Value: "Alex!!" ) ..
or otherwise writing: Let( $$record_991[1] = "Alex!!" ; "" )

Which means that if you were to now retrieve the value of $$record_991 - you would get "Alex!!" as the value returned.

Call: GetGlobalVariable( name ; repetition)

Custom Function: GetGlobalVariable( name ; repetition)
Evaluate("$$" & name & "[" & repetition & "]" )

Example Usage: GetGlobalVariable( "record_" & table::primaryKey ; 1 )
Which would (where primaryKey = 991 and the variable was set as above) return "Alex!!"

These examples aren't great, but they certainly simplify my scripts and I hope they'll help someone else out.

About author

Alex Babkov - Systems
www.realevolution.com.au

-