ScriptContext

Parent Previous Next

ScriptContext is used to define case distinctions for workflow expressions depending on the given workflow setting, point of execution and user actions


Members

Undefined

Value that is always active when no other value is chosen

InitInstance

Value that is active when the diagram / pool expression is executed. If there is a start form, it will be active after the start form has been submitted

PrepareForm

Value that is active when the diagram / pool expression is executed and there is a startup form. It is active before the start form is displayed

SaveForm

Value that is active when the end expression of a workflow form is executed after pressing the save button

SubmitForm

Value that is active when the end expression of a workflow form is executed after pressing the submit button

ActivityExpression

Value that is active when the activity expression is executed

MultiInstanceExpression

Value that is active when the activity expression is executed for each instance of a multi-instance activity


Samples

This sample shows differing workflow behaviour depending on the question if a start form is used or not.


If you have a start form, you could use this to initialize form data:

if ScriptContext.ActiveContext == ScriptContext.PrepareForm:

  # Prepare Form Data - no Process Instance available

  SFORM = { "User" :  "John Doe", "Department" : "public relations" }


If there is no start form or after the start form has been submitted, you could use this to define data at the beginning of the instance:  

if ScriptContext.ActiveContext == ScriptContext.InitInstance:

  import System

  date = System.DateTime.UtcNow



This sample shows a possibility to save the user who submitted the form into a variable for further use in the process. The sample is placed in the end action of the form.


if ScriptContext.ActiveContext == ScriptContext.SubmitForm:

  finishedBy = Session.CurrentUser.Account



A workflow expression of a user task can be executed multiple times, e.g. with a parallel user task. ScriptContext can be used to find out whether the execution is the initial token (ActivityExpression) or one of the multiple (MultiInstanceExpression). That way you can differentiate, e.g. which data should only be prepared once initially and which data should only be used in the parallel executions.