Returning structured data from sub-scripts

Expert

Use Exit Script with a JSON result so calling scripts can check for errors and extract multiple return values.

What you'll learn

  • How to construct a JSON result in Exit Script
  • How to read and check the result with Get(ScriptResult)
  • How to propagate errors from sub-scripts to their callers

A sub-script can return exactly one text value via Exit Script [ Text Result ]. Encoding that value as JSON lets you return multiple named values plus a status flag, so the calling script can distinguish success from failure without checking global variables.

1/3
1

Return a JSON object from the sub-script

Build a result object that always includes a "ok" boolean and any payload keys. Return it via Exit Script.

FileMaker Script
# Success path
Exit Script [ Text Result:
  JSONSetElement ( "{}" ;
    [ "ok"        ; True         ; JSONBoolean ] ;
    [ "recordId"  ; $newId       ; JSONNumber  ] ;
    [ "count"     ; $total       ; JSONNumber  ]
  )
]

# Error path
Exit Script [ Text Result:
  JSONSetElement ( "{}" ;
    [ "ok"    ; False              ; JSONBoolean ] ;
    [ "error" ; "Record locked"    ; JSONString  ]
  )
]

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

Sign in to FM Dojo