Writing Custom Code
How to get the most out of custom code blocks in Embeddables
Custom Code blocks provide various bits of context through arguments in the root functions. They are, in order:
# | Argument | Description |
---|---|---|
1 | userData | The current User Data |
2 | helperFunctions | An object containing various helper functions (see full list below) |
3 | triggerContext | An object containing data on what triggered the Computed Field or Action (see full list below) |
Available Helper Functions
setUserData(updates: Record<string, unknown>)
This can be used to update the current User Data.
It accepts a JSON object, which can contain one or more key/value pairs.
It’s treated as a subset of data that is merged into the existing User Data, although please note that any nested objects will be replaced not merged.
resetUserData()
This can be used to reset the current User Data to the same value as for a brand new user.
All previous data will be lost.
triggerAction(actionId: string)
This can be used to programmatically trigger an action from custom code.
One common use-case for this is when you want two actions to occur, but need one of them to complete before the other one starts.
This list is not exhaustive - more helper functions will be added to these docs soon.
Available Trigger Context variables
Please note that old_user_data
and new_user_data
currently only
contain the input keys for the Computed Field, not all of User Data. This may
change in the future.