How to chain script executions
Overview
This page describes how how to chain script executions so that the output of one script can be used as input for the next.
How script chaining works
This scenario is where one task (Task 1) executes script1 and produces an output wrapped in _output.scriptOutput.
A second task (Task 2) then executes script2 and explicitly references the first task’s output using the expression ${script_execution_1._output.scriptOutput}.
This ensures that the second script receives the required data dynamically.
Steps for chaining script executions
The main steps for setting up chained script executions are:
Step 1: Set up the Workflow definition
To set up the required Workflow definition, refer to the sample code below.
{
"_name": "sample_workflow",
"_description": "Sample Workflow",
"_userType": "workflow_userType",
"_namespaces": [
"{{nsfilter-workflowsvc}}"
],
"_taskDefs": [
{
"_name": "script_execution_1",
"_type": "SCRIPT_EXECUTION",
"_sequenceno": 1,
"_inputParams": {
"_userType": "workflow_userType6",
"_scriptName": "script1"
}
},
{
"_name": "script_execution_2",
"_type": "SCRIPT_EXECUTION",
"_sequenceno": 2,
"_inputParams": {
"param": "${script_execution_1._output.scriptOutput}",
"_userType": "workflow_userType6",
"_scriptName": "script2"
}
}
]
}
Step 2: Set up the two required scripts
Set up the two required scripts by referring to the sample code below.
async function script1(input, libraries, ctx) {
const getRes = { "param_workflow": "Test Value" };
return getRes;
}
async function script2(input, libraries, ctx) {
return input.actualParams;
}
Step 3: Set up the task outputs
Set up output of task 1
Set up the output of task 1 (script_execution_1) by referring to the sample code below.
{
"headers": {
"_reqId": "cbfcd4c3-60ca-4d6b-a345-6ed828064113",
"executionStatus": "success"
},
"scriptOutput": {
"param_workflow": "Test Value"
},
"_responseProperties": {}
}
Set up output of task 2
Set up the output of task 2 (script_execution_2) by referring to the sample code below.
{
"headers": {
"_reqId": "226c9538-f9e9-47b1-9c58-56e4a3831b12",
"executionStatus": "success"
},
"scriptOutput": {
"param": {
"param_workflow": "Test Value"
},
"_userType": "workflow_userType6",
"_scriptName": "script2"
},
"_responseProperties": {}
}
Notes on chaining script executions
The _inputParams defined in the Workflow will be available in the script as actualParams.
For example, in script2, input.actualParams.param contains the resolved output of script1, as shown in the sample below.
input.actualParams.param
//{ "param_workflow": "Test Value" }