Perform Script with parameter: JSON encoding and decoding
BeginnerPass structured data between scripts by encoding parameters as JSON objects and decoding them with JSONGetElement in the receiving script.
What you'll learn
- How to encode multiple values into a JSON script parameter
- How to decode the parameter in the receiving script with JSONGetElement
- How to define a consistent parameter contract for reusable scripts
- How to handle missing or malformed parameters defensively
- How to pass a JSON parameter through multiple levels of script calls
FileMaker's Perform Script step accepts a single text string as a parameter. By encoding that string as a JSON object you can pass multiple named values in one call, making sub-scripts self-documenting and eliminating the need for $$global variables as a handoff mechanism. The receiving script decodes the parameter with JSONGetElement at the start.
Build a JSON parameter before calling Perform Script
Use JSONSetElement to build the parameter object in the caller. Name keys descriptively -- the sub-script's developer reads these names to understand what to expect. Pass the variable directly into the Parameter field of Perform Script.
# Caller script
Set Variable [ $params ; Value:
JSONSetElement ( "{}" ;
[ "clientID" ; Clients::ClientID ; JSONString ] ;
[ "invoiceDate" ; Get ( CurrentDate ) ; JSONString ] ;
[ "sendEmail" ; 1 ; JSONBoolean ] ;
[ "calledBy" ; Get ( ScriptName ) ; JSONString ]
)
]
Perform Script [ "Create Invoice" ; Parameter: $params ]
Set Variable [ $result ; Value: Get ( ScriptResult ) ]Sign in to track your progress and pick up where you left off.
Sign in to FM Dojo