RunJavaScript Activity
Purpose: Executes JavaScript code. This activity allows you to write and execute JavaScript code directly within your workflow, providing flexibility for custom logic and data manipulation.
Input Properties
The JavaScript code to execute. This can be any valid JavaScript code that returns a value or performs operations.
Type: string
Default: "" (empty string)
Required: No (but nothing happens if empty)
Note: The script has access to workflow context, variables, and can use setOutcome() to control flow.
A list of possible outcomes that can be set by the script. Use setOutcome(string) or setOutcomes(...) in your script to set outcomes.
Type: ICollection<string>
Note: Define the outcomes that your script might set. If not set, defaults to "Done".
Output Properties
The result value returned by the JavaScript script, if any.
Type: object
Note: Contains the return value of the script execution. Will be null/undefined if the script doesn't return a value.
Usage Example
Scenario: Calculate a value using JavaScript
Configuration:
- Script:
var x = getVariable("Input1");
var y = getVariable("Input2");
return x * y + 10;
- PossibleOutcomes: ["Done"]
Result:
- The script executes and calculates the result
- Result output contains the calculated value (x * y + 10)
- Activity completes with "Done" outcome
Scenario: Conditional outcome based on calculation
Configuration:
- Script:
var count = getVariable("ItemCount");
if (count > 100) {
setOutcome("High");
} else {
setOutcome("Low");
}
- PossibleOutcomes: ["High", "Low"]
Result:
- Script evaluates the condition
- Activity completes with either "High" or "Low" outcome
- Subsequent activities can branch based on the outcome
Important Notes
- The script has access to
getVariable(name)to read workflow variables - The script has access to
setVariable(name, value)to write workflow variables - Use
setOutcome(string)to set a single outcome - Use
setOutcomes(...)to set multiple outcomes - If no outcome is set, defaults to "Done"
- The script can return a value which will be available in the Result output
- Script execution uses the Jint JavaScript engine
- For complex logic, consider creating custom activities instead of inline scripts
- Script errors will cause the activity to fault
Related Activities
- RunCSharp - Execute C# code instead of JavaScript
- SetVariable - Set variables that can be used in scripts
- If - For simple conditional logic without scripting