Functions in the Script node
You can use various functions in the Script node.
- The standard JavaScript functions and constructs.
- The API functions (the range depends on your license).
- Additional functions listed below:
getParameters()
This function obtains the parameters that were specified for the Script node.
This will give you access to the variables of the workable, the files you need to process, etc.
getParameters()
getJSONFromContainer()
This function obtains JSON data from a container in the database.
In most cases, this data originates from work data that was saved by a previous Data
or Script node. In those cases you have a reference to that data, and this call will
load the data into the script. The data_reference
parameter can be
an object containing a data provider value composer node, or a string. The
advantage of using the object is that the references stored in the workable are
typically inside objects and as such they can be used as is.
getJSONFromContainer({\"type\" : \"com.nixps.quantum.data_provider.0\", \"url\" : \"cfqworkdata:///1234/\"}
getJSONFromContainer(\"cfqworkdata:///1234/\"})
setResultFiles(files)
This function sets the file reference(s) that should be assigned as result of this node. The files parameter can be a single string for a single file, or an array of strings for multiple output files.
setResultFiles("cloudflow://PP_FILE_STORE/MyFile.txt");
setResultFiles(["cloudflow://PP_FILE_STORE/file1.txt" , "cloudflow://PP_FILE_STORE/file1.txt"]);
setResultContainerFromJSON(json_data)
This function saves the specified JSON data in the workable data and adds a reference to the saved JSON data and to the result of this node. The json_data parameter will be saved as is for later use.
setResultContainerFromJSON({"key1" : "value 1", "key2", "value 2"});
setResultVariables(variables)
This function sets the variables that should be assigned as a result of this node.
setResultVariables({"var1" : 1, "var2" : "Some Text"});
setOutput(connectorName)
This function controls the output path of the workable when the script is finished. For example, when you specify failure, the workable will be sent to the failure output.
setOutput('failure');
console.log(…)
This function adds the specified text to the workable log. The parameters can be text or complete JSON objects that are stringified. Multiple arguments are space separated.
The main differences between this function and the print() function are the following:
print() | console.log() |
---|---|
Can handle one argument | Can handle 0, 1 or multiple arguments |
Encloses a string in double quotes | Does not quote strings |
console.log() is API compatible with console.log in the browser.
console.log('nr seps', 2);
addMessageToLog(severity, message)
This function adds a message to the workable log. The difference between this function and the print() function is the following:
print() | addMessageToLog(severity, message) |
---|---|
Is always info | Possible to specify a severity |
- debug
- info
- warning
- error
addMessageToLog('info', 'some text');
setProgress(value, message)
This function sets progress info. This contains a progress value between 0 and 1 and activity information. This progress and activity will be fed back to the dashboard (when the script takes a long time).
setProgress(.5, 'working');
addSystemMessage(severity, message)
This function adds a message to the system log.
- debug
- info
- warning
- error
addSystemMessage('warning', 'hey, you need to know this');
addEventMessage(severity, message, url)
This function adds an event message to the system log linked to the specified asset. The event type will be kGenericAssetMessage.
- debug
- info
- warning
- error
addEventMessage('error' , 'asset is broken', 'cloud flow://PP_FILE_STORE/test/asset.pdf');