Skip to content

Execute Script in Automation

Usage Instructions

The automation will execute JS code in the step using the script engine

Usage Instructions

The code snippets running in automation can use all functions in Script, and additionally extend the automation-specific automatic context object

getVar

Get automation context variables

ParameterTypeDescription
varNameStringContext variable name
js
automatic.getVar(varName);

Usage Example

js
const varList = automatic.getVar("varList");

Notes

If the variable name to be obtained does not exist in the context, a null value will be returned

setVar

Set automation context variables

ParameterTypeDescription
varNameStringContext variable name
valueObjectVariable value
js
automatic.setVar(varName, value);

Notes

If the variable name to be set exists in the context, it will overwrite the existing variable value

setProgress

Set the execution progress of the current automation

ParameterTypeDescription
progressDoubleExecution progress, range 0~100
messageStringProgress description text
js
automatic.setProgress(50.56, "Processing files");

setReturnValue

Set the return value of the current automation. This function has the same capability as the Set Automation Return Value step

ParameterTypeDescription
returnValueObjectAutomation return value
js
automatic.setReturnValue(1);
automatic.setReturnValue(true);
automatic.setReturnValue(new Date());
automatic.setReturnValue({
  name: "张三",
});
automatic.setReturnValue([1, 2, 3, 4, 5, 6]);

Notes

When multiple automatic.setReturnValue are used, only the last call will take effect; so if multiple values need to be returned, a data structure needs to be built in the code snippet and returned as a whole