Passing complex data via JSON script parameters

Expert

Use JSONSetElement to bundle multiple values into a script parameter, and JSONGetElement to unpack them inside the called script.

What you'll learn

  • How to build a JSON parameter using JSONSetElement
  • How to extract individual values with JSONGetElement inside a sub-script
  • Why JSON parameters are safer than global variables for multi-user solutions

FileMaker scripts accept a single text parameter. By encoding a JSON object into that text, you can pass any number of named values to a sub-script without relying on global variables, which cause concurrency problems in multi-user solutions.

1/3
1

Build the parameter in the calling script

Construct a JSON object with JSONSetElement before calling the sub-script. Pass it as the Script Parameter.

FileMaker Script
Set Variable [ $param ; Value:
  JSONSetElement ( "{}" ;
    [ "invoiceId"  ; Invoices::id       ; JSONNumber ] ;
    [ "userId"     ; $$currentUserId    ; JSONString ] ;
    [ "sendEmail"  ; 1                  ; JSONBoolean ]
  )
]
Perform Script [ "Process Invoice" ; Parameter: $param ]

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo