JavaScript
In this section, we cover some of the built-in variables and functions available to the JavaScript expression syntax.
When creating workflows, you'll often need to write dynamic expressions. This page provides an overview of enabling JavaScript expressions and what functions and objects you can use.
Installing the JavaScript Feature
The JavaScript Expressions feature is provided by the following package:
You can enable the feature as follows:
Configuration
The UseJavaScript
extension provides an overload that accepts a delegate that lets you configure JintOptions
. These options let you configure the underlying Jint engine.
For example:
Elsa uses Jint to implement the JavaScript expression evaluator.
Globals
The following functions and objects are available as globals to all JavaScript expressions:
get{InputName}
get{VariableName}
set{VariableName}
JSON
The JSON
type provides static methods to parse JSON strings into JavaScript objects and to serialise JavaScript objects into JSON strings.
variables
The variables
object provides static access to the workflow variables. For example, if your workflow has a variable called OrderId, you can get and set that workflow variable using the following JavaScript expression:
getWorkflowDefinitionId
Returns the workflow definition ID of the currently executing workflow.
getWorkflowDefinitionVersionId
Returns the workflow definition version ID of the currently executing workflow.
getWorkflowDefinitionVersion
Returns the workflow definition version of the currently executing workflow.
getWorkflowInstanceId
Returns the workflow instance ID of the currently executing workflow.
setCorrelationId
Sets the correlation ID of the currently executing workflow to the specified value.
getCorrelationId
Gets the correlation ID of the currently executing workflow.
setVariable
Sets the specified workflow variable by name to the specified value.
getVariable
Gets the specified workflow variable's value by name.
getInput
Gets the specified workflow input by name.
getOutputFrom
Gets the specified activity output by name from the specified activity by name.
getLastResult
Gets the output of the last activity that executed.
isNullOrWhiteSpace
Returns true
if the specified string is null, empty or consist only of whitespace characters, false
otherwise.
isNullOrEmpty
Returns true
if the specified string is null or empty, false
otherwise.
parseGuid
Parses the specified string into a Guid
.
newGuid
Creates a new Guid
.
newGuidString
Creates a new Guid
as a string
representation.
newShortGuid
Creates a new short GUID as a string
representation.
bytesToString
Converts a byte array to a string.
bytesFromString
Converts a string to an array of bytes.
bytesToBase64
Converts a byte array to a base64 string.
bytesFromBase64
Converts a base64 string to a byte array.
stringToBase64
Converts a string to a base64 string.
stringFromBase64
Converts a base64 string to a string.
Last updated