A button starts a follow-up script. Today it needs a contact ID; tomorrow it may need an action and an optional setting. Passing a named JSON object makes those inputs easier to change without relying on a particular line order.
This example prepares and validates a request. It deliberately stops before creating a record. Use a working copy with FileMaker Pro 19.5 or later for the type checks shown here. FileMaker Pro is sold separately.
1. Write the input contract first.
Our fictional script, Contact | Prepare follow-up, accepts two required text keys: contactId and action. The only supported action in this example is followUp. A contact ID is an identifier, so 00042 must stay text.
Example parameter
{"contactId":"00042","action":"followUp"}Decide these rules before building the receiver. If you later add an optional key, document its default so existing callers keep working. Do not silently reinterpret an old key.
2. Build the parameter at the call site.
In Perform Script, select the receiving script and use this calculation for its parameter. These literal values let you test without depending on a record:
FileMaker calculation
JSONSetElement ( "{}" ;
[ "contactId" ; "00042" ; JSONString ] ;
[ "action" ; "followUp" ; JSONString ]
)After the sample works, replace "00042" with your own contact ID field. Confirm that the button’s layout context supplies the intended contact. The parameter carries a value, not a live reference to a field.
3. Validate before using the values.
Read the parameter once, reject an invalid top-level object, then check the individual types. JSONGetElementType requires version 19.5 or later. A missing key, null, a number and an empty string are different inputs.
Script reading guide: recreate these steps in Script Workspace; this text is not a pasteable native script.
FileMaker script
Set Variable [ $p ; Value: Get ( ScriptParameter ) ]
If [ JSONGetElementType ( $p ; "" ) ≠ JSONObject ]
Exit Script [ Text Result: "Invalid parameter: expected an object" ]
End If
If [ JSONGetElementType ( $p ; "contactId" ) ≠ JSONString or
JSONGetElementType ( $p ; "action" ) ≠ JSONString ]
Exit Script [ Text Result: "Invalid parameter: expected text keys" ]
End If
Set Variable [ $contactId ; Value: JSONGetElement ( $p ; "contactId" ) ]
Set Variable [ $action ; Value: JSONGetElement ( $p ; "action" ) ]
If [ IsEmpty ( Trim ( $contactId ) ) or $action ≠ "followUp" ]
Exit Script [ Text Result: "Invalid parameter: missing ID or unsupported action" ]
End If
Exit Script [ Text Result: "Ready: " & $contactId ]The sample returns a simple text result. In a larger app, use a consistent result object with separate success, error and data keys. Keep that output contract documented alongside the input contract.
4. Read the result in the caller.
Immediately after Perform Script, capture Get ( ScriptResult ) in a variable before another script replaces it. With the sample parameter, expect Ready: 00042. This confirms parameter handling only; it does not confirm that the contact exists or that a follow-up was saved.
Before adding record changes, locate the contact by its stable ID, handle no match, check the intended privileges and confirm the operation’s own result. Do not use a supplied ID as permission to access a record.
5. Test the boundary, not just the happy path.
- Replace the ID with the number
42: expect the text-type error. - Remove
contactIdor set it to null: expect rejection. - Use a blank or whitespace-only ID: expect the missing-ID error.
- Send an array or malformed JSON: expect the object error.
- Change the action to
delete: expect the unsupported-action error.
Paste fictional parameters into the JSON formatter to inspect their structure. Its syntax check cannot verify your script contract. When adding optional values, check their type only when supplied and apply an explicit default when absent.
PUT IT INTO PRACTICE
Try it with Filesoft.
Open the JSON formatterWant a guided learning path? Explore the free FileMaker courses.
Continue reading
Reference: Get ( ScriptParameter ) · Perform Script · Get ( ScriptResult ) · JSONGetElementType. Examples are learning aids; check them in your own FileMaker working copy.