REFERENCE
Developer Reference
Authentication, APIs, SDKs, Flow Agent processors and parameter resolution, in full.
Execute Script
Run a custom script and feed its return value back into the flow.
Execute Script is the processor that runs custom JavaScript.
Basic usage
Execute Script runs the configured script in the chosen JavaScript engine.
Configuration
The node's property panel:
Name
The name shown on the canvas, used to identify this processor within the workflow.
Description
Explains what this processor is for, making the workflow easier to read.
Properties
Engine (required)
The JavaScript engine. Only
ECMA5is supported at present.Script (required)
The JavaScript to run.
Accessing data
Execute Script exposes a global object named
payloadholding everything in the workflow:- the current workflow's payload data
- built-in variables such as
prevMessageandprevPayload
Reading data
Given this data in your workflow:
{
"user": {
"name": "Alice",
"email": "zhang@example.com"
}
}read it like this:
// "Alice"
const userName = payload.user.name
// "zhang@example.com"
const userEmail = payload.user.emailModifying data
You can also modify the payload, and the changes carry into later processors:
// change existing data
payload.user.name = "Bob"
// add data
payload.processedAt = new Date().toISOString()
payload.status = "completed"Built-in variables
Asgard's built-in variables are reachable through
payload:// the user's last message
const lastMessage = payload.prevMessage
// the previous processor's payload
const previousData = payload.prevPayload
// nested data
const specificValue = payload.prevPayload.somePropertyLimitations
Asgard's built-in functions (
history(),vecToStr()and the like) are not available inside Execute Script. Use another processor type when you need them.In the Workflow CRD
- name: proc-transform
type: execute-script
labels:
display_name: Tidy the query result
configs:
- name: engine
value: ECMA5
- name: script
value: |-
var names = [];
for (var i = 0; i < payload.rows.length; i++) {
names.push(payload.rows[i].name);
}
payload.summary = names.join(", ");A worked example
Turn an array from the previous step into one sentence.
Field Value Engine ECMA5Script below var names = [];
for (var i = 0; i < payload.low_stock.length; i++) {
names.push(payload.low_stock[i].sku_name);
}
payload.summary = names.join('、');The script reads
payload.low_stockand writes the result topayload.summary. Later processors read the sentence frompayload.summary.Notes
- Engine has exactly one valid value,
ECMA5, running on goja. Anything else givesUnknown script engine. - The script reads and writes data through
payload. Write the result to a field ofpayloadso that later processors can read it.
- Engine has exactly one valid value,