Execute
The Execute Activity executes a script written in JavaScript. The script can read all Variables, Start Parameters and Subscription Settings in the Instance’s Context and write its results to new Context Variables.
Activity config
General
- Name - Name of the Activity.
- Version - Version of this Activity used in the Process. If a new version of this Activity is available and you want to use it, you have to manually update the version here. When a new Activity is added to the Process, automatically the latest version is placed.
- Timeout in second - Once this time is elapsed, the Activity is closed and the Instance changes into the
faulted
-state. The default Timeout is two minutes. The timeout can be shortened and extended by entering a custom duration. If the Activity is left after a timeout, the first Outcome is followed. If multiple Outcomes have the same name as the first Outcome, all of them are followed. However, a continuation after a timeout does not effect the Outcome Scripts, meaning only Outcomes with Outcome Scripts evaluating totrue
are followed. - Hide in process graph - Controls if the Activity is hidden (Yes) or shown (No) in the Process Graph on the Execution Screen.
- Continue on error - If this is set to Yes, the execution of the Instance continues even if the Activity failed. If set to No, the Instance fails when the Activity fails by entering the
faulted
-state. In the case of a continuation after an error, the first Outcome is followed. If multiple Outcomes have the same name as the first Outcome, all of them are followed. However, a continuation after an error does not effect the Outcome Scripts, meaning only Outcomes with Outcome Scripts evaluating totrue
are followed.
Execute
Execute Activity specific configurations
GENERAL
General interaction configuration, shared with most other Activities
- Disable activity - Disables (Yes) or enables (No) the Activity. When disabled, the Activity is not executed and passed like a Connection by following the first Outcome. If multiple Outcomes have the same name as the first Outcome, all of them are followed. Disabling the Activity does not effect the Outcome Scripts, i.e., still only Outcomes with Outcome Scripts evaluating to
true
are followed. - Retry on error - If set to Yes, an automatic retry is executed up to ten times. If set to No, no retries are done. Retries are issued when the Activity failed so that the Instance would enter the
faulted
-state if the retry is disabled. - Additional text for task list - Description of this Activity shown to the Users in their task list. You can enter this text directly or use Process Context Expressions to compile it.
SETTINGS
Allows access to the JavaScipt code in this Activity
- Script - Clicking on Edit opens the editor for the JavaScipt code. The editor offers the buttons:
- Insert template script - Inserts a JavaScript template to start the development of the script.
- Test script - Open a test environment to test the entered JavaScipt code.
Each script has to be a valid JavaScript function with the name execute()
and a String as return value. This String is the name of the Outcome used to leave the Activity. Therefore, if there is no Outcome with a name matching the returned String, the Instance will fail. The minimal script defining a function with the name execute()
and return the name of the Default
Outcome looks like this:
function execute() {
return 'Default';
}
A scripts can obviously select an Outcome different to Default
, if the Outcome and the returned String are set accordingly. Furthermore, the code can be designed to return different Outcome names to selected different branches to continue the Process. Hence, the Activity can have an arbitrary amount of Outcomes, also with different names. Those Outcomes with a name matching the returned string are selected and the script of these Outcomes is evaluated. Be aware that the scripts of the Outcomes are complete independent from the script in the Activity, even though both are written in JavaScript. Each matching Outcome with a script evaluating to true
is followed. If more than one Outcome script evaluates to true
, the process is paralleled. If no Outcome script evaluates to true
, Instance is ended by entering the closed
-state.
The script configured in the Execute Activity can read Variables, Start Parameters and Subscription Settings:
context.Entities["MyEntity"]
- Access the Entity Variable with the nameMyEntity
context.Entities["MyEntity"].MyAttributeName
- Access the AttributeMyAttributeName
of the Entity VariableMyEntity
contextParameters["MyContext"].MyContext
- Access the Context Variable with the nameMyContext
contextParameters["MyContext"].MyContext.MyAttributeName
- Access the AttributeMyAttributeName
of the Context VariableMyEntity
context.GlobalSettings.SettingList["SubscriptionSettingName"]
- Access the Subscription Settings with the nameSubscriptionSettingName
contextParameters["StartParameterName"].StartParameterName
- Access the Start Parameter with the nameStartParameterName
context.Activity
- Access the properties of the current Activity:context.Activity.Id
- ID of the Activitycontext.Activity.Name
- Name of the Activitycontext.Activity.TimeoutSeconds
- Once this time is elapsed, the Activity will be closed and the Process continued. The timeout is deactivated by setting it to zero seconds.context.Activity.ContinueOnError
- If set totrue
, the Instance will continue even if this Activity failed. If set tofalse
, this Instance will fail if the Activity fails.
context.ProcessInstance
- Access the property of the current Instance:context.ProcessInstance.Id
- ID of the Instancecontext.ProcessInstance.Name
- Name of the Instancecontext.ProcessInstance.TaskDisplayInformation
- Holds the task description for the current Activity. The task description is configured in the Additional text for task list property of the Activity.context.ProcessInstance.ParentProcessInstanceId
- ID of the Instance that started this Instance, ornull
if this Instance has no parent Instance and was started by a User.context.ProcessInstance.FromParentActivityId
- ID of the Activity that started this Instance, ornull
if this Instance has no parent Activity.context.ProcessInstance.LastOutcome
- Name of the last Outcome this Instance passed thoughcontext.ProcessInstance.Status
- Current state encoded as an Integer value:- 1 -
Started
- 2 -
In Progress
- 3 -
Closed
- 4 -
Canceled
- 5 -
Faulted
- 1 -
context.ProcessInstance.IsDebugMode
- Indicates if this Instance is a debug Instance (true
) or not (false
)
The script configured in the Execute Activity can write Context Variables and log messages:
-
addoutput( 'NewContextVariable', MyVariable )
- Creates a new Context Variable with the nameNewContextVariable
and the value of the JavaScript variableMyVariable
. The variableMyVariable
has to be a singe value or of the typeValueDefinition
:- Simple Context Variable with only one value and without any Attributes can be implicitly defined as:
addoutput('MyVariableName', 1234);
- Context Variable with one or more Attributes is defined as an array. Each Attributes is one entry in the array:
var MyVariable = [ { FieldName: 'FirstAttribute', Value: 'FirstValue'}, { FieldName: 'SecondAttribute', Value: 22.22}, { FieldName: 'ThirdAttribute', Value: true } ]; addoutput('MyVariableName', MyVariable );
- Complex Attributes in Context Variable are also defined as entries in arrays:
var MyVariable = [ { FieldName: 'SimpleAttribue', Value: 'string value'}, { FieldName: 'Address', Value: [ { FieldName: 'Street', Value: 'My Steet'}, { FieldName: 'Number', Value: '18b'} ] } ]; addoutput('MyVariableName', MyVariable );
-
log( message )
- Logsmessage
as status information on the Subscription Log -
logerror( message )
- Logsmessage
as an error on the Subscription Log