Activities

Activity is the first key object a scheme comprises. It determines the order, in which Actions are executed in your process. When being executed, your process conducts efficient work and leaves artifacts in your system. If you open the Activity parameters window in Designer, the following properties are available for modification:

  • Name - should necessarily be specified as far as all Activities are identified within a scheme by it. Besides, Name is case sensitive and should be unique;
  • State - the name of a particular state, which the Activity belongs to. It may be non-unique or even absent at all;
  • Initial - if checked, the process will be executed starting with this Activity. There can be only one initial Activity in any scheme;
  • Final - if checked, this Activity will be the final one within a process. For a regular process, it means that its status will be changed to finalized, and it may further be deleted or left in the system. As for the subprocesses, they will be deleted automatically (read more in the Subprocesses section). A scheme may have any number of final Activities, or not have them at all;
  • For set state - means that this Activity is initial for the state whose name is set in the State parameter. The process will be set to this Activity if you call the SetState method with the name of the state from the State parameter;
  • Auto scheme update - enables automatic scheme update if the process is in this Activity. Refer to the Scheme Updates section for more details;
  • Implementation - contains the list of Actions, that will be executed immediately after the process reaches this Activity. Each Implementation line includes the following fields:
    • Order - determines the order in which Actions are executed;
    • Action - the name of the Action being called;
    • Action Parameter - a string value of the additional parameter conveyed to Action; may contain JSON. Read more about Actions in the Action Creation section.
  • PreExecution Implementation - contains the same fields as Implementation. However, Actions in this section are called only in Pre-Execution mode.

State & Activity

Activity is a physical state of the process. When we need to clearly identify the stage of the process, we say what Activity it has reached so far. State is a business state of the process. One State can have a number of Activities belonging to it. Filling a State is optional.

If you want your process to have a "SomeState" state, which may be called via the GetAvailableStateToSet method and be set via the SetState method, the following conditions should be met:

  • At least one Activity should have a State = "SomeState";
  • One and only one Activity with a State = "SomeState" should have a For set state checked. This Activity will be initial for this state. After calling the SetState method, the process will be set into this state, and if there are any automatic transitions, they will be executed immediately.

As the process transitions from one Activity to another, the following rules of state change apply:

  • If State of the Activity being executed is not filled - the current state does not change;
  • If State of the Activity being executed is filled and it is equal to the current one - the current state does not change;
  • If State of the the Activity being executed is filled and it is not equal to the current one - the current state changes after the execution of all Actions listed in the Implementation section of this Activity.

Let's take a look at the examples.

Scheme1

For example, you document may exist only in three states - Created, Signing, Signed. Then, there are four Activities, because there's a timer which transitions the document from the Signing state to an Activity, where a letter is sent, notifying that the document is being signed for too long. The SendNotification Activity does not have a State filled in, meaning that when the timer transitions the document into it, the current state will not change. If you set For set state = true for Created, Signing and Signed activities, all three states will become available for setting. If you set the document into a Signing state via the SetState method, the timer will be reset and start counting the time elapsed from the moment the state was set. It is impossible to set the document via the SetState method in the SendNotification activity.

Scheme2

This scheme also has only three states - Created, Signing, Signed, but more Activities. After the process transitions to the Signing Activity and executes all available Actions, its state is changed to Signing. Depending on conditions, it will further transition to one of the two Activities - SigningByManager or SigningByAccountant, but its state will change only after it reaches the Signed Activity. If you set For set state = true for Created, Signing and Signed Activities, all three states will become available for setting. If you change the document state to Signing via the SetState method, the process will automatically check conditions and transition to one of the two Activities - SigningByManager or SigningByAccountant. From the point of view of Workflow Engine, Signing, SigningByManager and SigningByAccountant Activities belong to the Signing state.

The State functionality should not necessarily be utilized. You may or may not utilize it, depending on the requirements to your system.

Major methods of utilizing Activity and State

  • Getting current Activity, State, and executed Activity and State from ProcessInstance:
    ActivityDefinition currentActivity = processInstance.CurrentActivity;
    string currentActivityName = processInstance.CurrentActivityName;
    string currentState = processInstance.CurrentState;
    ActivityDefinition executedActivity = processInstance.ExecutedActivity;
    string executedActivityState = processInstance.ExecutedActivityState;
  • Getting current Activity and State from WorkflowRuntime:
    ActivityDefinition currentActivity = runtime.GetProcessInstanceAndFillProcessParameters().CurrentActivity;
    string currentActivityName = runtime.GetCurrentActivityName(processId);
    string currentState = processInstance.GetCurrentStateName(processId);
  • Gaining access to all scheme Activities:
    List<ActivityDefinition> activities = processInstance.ProcessScheme.Activities;
    ActivityDefinition initialActivity = processInstance.ProcessScheme.InitialActivity;
    ActivityDefinition someActivity = processInstance.ProcessScheme.FindActivity("ActivityName");
  • Setting the process to an Activity. Unlike SetState, it works without State filled in:
    var parameters = new Dictionary<string, object> ();
    var doNotSetRunningStatus = false;
    var activityToSet = processInstance.ProcessScheme.FindActivity("ActivityName");
    WorkflowInit.Runtime.SetActivityWithExecution(identityId,impersonatedIdentityId,parameters,activityToSet,processInstance,doNotSetRunningStatus);
    WorkflowInit.Runtime.SetActivityWithoutExecution(activityToSet,processInstance,doNotSetRunningStatus);
Top