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:
SetStatemethod with the name of the state from the State parameter;
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:
SetStatemethod, 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:
Let's take a look at the examples.
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.
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.
ActivityDefinition currentActivity = processInstance.CurrentActivity; string currentActivityName = processInstance.CurrentActivityName; string currentState = processInstance.CurrentState; ActivityDefinition executedActivity = processInstance.ExecutedActivity; string executedActivityState = processInstance.ExecutedActivityState;
ActivityDefinition currentActivity = runtime.GetProcessInstanceAndFillProcessParameters().CurrentActivity; string currentActivityName = runtime.GetCurrentActivityName(processId); string currentState = processInstance.GetCurrentStateName(processId);
List<ActivityDefinition> activities = processInstance.ProcessScheme.Activities; ActivityDefinition initialActivity = processInstance.ProcessScheme.InitialActivity; ActivityDefinition someActivity = processInstance.ProcessScheme.FindActivity("ActivityName");
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);