Execution of Automation Scripts
A workflow allows you to execute automation scripts registered within the Corredor server. The ability to execute automation scripts can come in handy when you need to implement complex business logic, but still wish to keep the visual description of a workflow.
The automation script
Refer to the Automation scripts for details regarding automation script internals and how to deploy them to the Corredor server. |
The automation script must define a manual trigger for the system resource. Feel free to use the following example as a starting point.
export default {
label: 'Called From Workflow',
description: 'This script will be called from workflow function',
triggers ({ on }) {
/**
* Due to how the Corredor scripting system is designed right now,
* triggers still need to be defined (even if the script is
* executed explicitly from the workflow).
*/
return on('manual').for('system')
},
exec (args, { logger }) {
logger.info('success')
}
}
The workflow
To execute an automation-script, add a function step that calls the Corredor automation script executor
function.
Insert the script reference under the script argument.
-
Navigating to the
and find the automation script you wish to execute and copy its reference. -
Construct it manually using the pattern of
/server-scripts/path-to/the-script/script-name.js:default
. For the example above, the reference is/server-scripts/invoked-from-the-workflow.js:default
.
Refer to the Automation scripts documentation in case you cannot see your automation scripts. |
Place a trigger and connect it to the function step you’ve defined earlier.
To test if everything works correctly, click on the run icon in the top right corner of the trigger.
If everything works correctly, you will see a "success"
string logged by the Corredor server after the test has been run.
Passing custom arguments
Add an expression step between the trigger and the function step.
scriptArgs (Vars) (1)
scriptArgs.from (Boolean) = false (2)
scriptArgs.workflow (String) = "some string" (3)
1 | Define a new set of variables that will be passed to the automation script. |
2 | Define a from variable with the value of false . |
3 | Define a workflow variable with the value of "some string" . |
Update the function step and set the args
argument to scriptArgs
(the variables we’ve defined in the expression step).
export default {
label: 'Called From Workflow',
description: 'This script will be called from workflow function',
triggers ({ on }) {
/**
* Due to how the Corredor scripting system is currently designed,
* triggers still need to be defined (even if the script is
* executed explicitly from the workflow).
*/
return on('manual').for('system')
},
exec (args, { logger }) {
// unpack arguments
const { from, workflow } = args
// log all arguments
logger.info('these are the special arguments we received', { from, workflow })
}
}
To test whether everything works correctly, click on the run icon in the top right corner of the trigger.
If everything works correctly, you will see a 'these are the special arguments we received' { from: false, workflow: 'some string' }
string logged by the Corredor server.
Reading an execution result
Specify the target variable to collect the output of the automation script in the function step that executes it. The automation script should return an object.
Standard automation script rules for return values apply.
If the automation script returns a |
export default {
// ...
exec (args, { logger }) {
logger.info('returning some values from the script')
return {
a: 123,
b: true
}
}
}