Live Instance Management (LIM) in Sourcecode.KO

The KO.dll assembly is the runtime dll that executes process instances according to the process definition. Essentially, it is what passes process instance context into the code behind server events in a workflow definition. The methods in KO.dll are generally accessed through custom code events in code-behind for server events in a workflow. Developers can access these methods through the ‘K2’ object that exists for all code in a process definition.

In terms of Live Instance Management, the relevant methods in SourceCode.KO allow you to force the process to go to another activity, optionally expiring any other active activities or not. You cannot use SourceCode.KO to force a process to migrate itself to a different version of the workflow.
Class Name Method Name Argument Name Argument Description
ActivityEscalationActionContext GotoActivity name The Destination Activity Name to where the Process should go to.
expireAll Expire all Activity Instances on the process instance, or only the current Instances for the Activity
ServerEventContext GotoActivity name The Destination Activity Name to where the Process should go to.
expireAll Expire all Activity Instances on the process instance, or only the current Instances for the Activity
ProcessEscalationActionContext GotoActivity name The Destination Activity Name to where the Process should go to.
expireActivity The name of the Activity to expire
ProcessFinishRuleContext GotoActivity name The Destination Activity Name to where the Process should go to.

Server Event Context

K2.GotoActivity(string name, bool expireAll)

Expires active instances of the activity that the server event is located in, and forces the process instance to create a single instance of the named activity in the ‘name’ parameter.

Parameters:
  • name is the name of an activity to go to.
  • expireAll specifies whether or not all active activity instances should be expired when the GoToActivity method is executed.
    • If ‘expireAll’ is true, all activity instances for the process will be expired along with the activity currently in context of the escalation rule.
    • If ‘expireAll’ is false, only instances for the activity in the current escalation context are expired, and any concurrent activities remain in their current state.
Copy

K2.GotoActivity(string name, bool expireAll)

//force the current instance to go to SomeActivity, and expire all current activities
K2.GotoActivity("SomeActivity", true);

//force the current instance to go to SomeActivity, but only expire the current activity
K2.GotoActivity("SomeActivity", false);

When a server event is expired, the process instance will continue with the process execution as specified in the process definition. If there is no condition on the lines emanating from an activity that has a server event with this method call, K2 will automatically create instances of the activities following the server event AS WELL AS the activity in the ‘name’ parameter.
It is therefore possible that multiple instances of the following activity in the process definition may be created, or that two activities exist when only one is expected. This behavior is by design, and developers can cater for this possibility by adding rules to lines that flow out of an activity that has a server event with this method call.

It is possible to inadvertently create ‘duplicate’ instances of activities. If there is already an instance of the activity in the ‘name’ parameter active in the process, and this method is called, a duplicate instance of the Activity in the ‘name’ parameter will be created. This is expected behavior, and developers should cater for this expected behavior in their code where applicable

Activity\Event Escalation Context

K2.GotoActivity(string name, bool  expireAll)

Expires active instances of the activity that the escalation action code is executing in, and forces the process instance to create an instance of the named activity in the ‘name’ parameter.

Parameters:
  • name is the name of an activity to go to.
  • expireAll specifies whether or not all active activity instances should be expired when the GoToActivity method is executed.
    • If ‘expireAll’ is true, all activity instances for the process will be expired along with the activity currently in context of the escalation rule.
    • If ‘expireAll’ is false, only instances for the activity in the current escalation context are expired, and any concurrent activities remain in their current state.
Copy

K2.GotoActivity(string name, bool expireAll)

//force the current process instance to go to SomeActivity when the escalation action code executes, but only expire the current activity
K2.GotoActivity("SomeActivity", false);
//force the current process instance to go to SomeActivity when the escalation action code executes, and expire all other activities
K2.GotoActivity("SomeActivity", true);

Process Escalation Context

K2.GotoActivity(string name)

Expires all active activity instances (including concurrent activity instances) in the process, and forces the process instance to start the named activity specified with the ‘name’ parameter.

Parameters:
  • name is the name of an activity to go to.
Copy

K2.GotoActivity(string name)

//force the current process instance to go to SomeActivity when the escalation action code executes, and expire all current activities
K2.GotoActivity("SomeActivity");

It is possible to inadvertently create ‘duplicate’ instances of activities. If there is already an instance of the activity in the ‘name’ parameter active in the process, and this method is called, a duplicate instance of the Activity in the ‘name’ parameter will be created. This is expected behavior, and developers may need to cater for this behavior where applicable.

K2.GotoActivity(string name, string expireActivity)

Expires only active instances for the named activity in the ‘expireActivity’ parameter, and forces the process to start an instance of the named activity in the ‘ExpireActivity’ parameter. Any concurrent activities remain in their current state.

Parameters:
  • name is the name of an activity to go to.
  • expireActivity is the name of an activity instance to expire when the escalation code executes.
Copy

K2.GotoActivity(string name, string expireActivity)

//force the current process instance to go to SomeActivity when the escalation action code executes, but only expire the activity "ActivityToExpire"
K2.GotoActivity("SomeActivity", "ActivityToExpire");
If the activity specified in the ‘name’ parameter is not active at the time the escalation code executes, the method will still create an instance of the activity specified with the ‘expireActivity’ parameter. This behavior is by design, and developers may need to cater for this in the Escalation action code.

Process Finish Rule context

K2.GotoActivity(string name)

Forces the Process Instance to create an instance of the named activity in the ‘name’ parameter.

Parameters:
  • name is the name of an activity to go to.
Copy

K2.GotoActivity(string name)

//force the current process instance to go to SomeActivity when the process finish rule code executes
K2.GotoActivity("[SomeActivity]");

This code will never execute when concurrent activities are active, since the context of the code is the process finish rule, and a finish rule can only ever be executed once all current activities are completed.

When using this method, it is possible to inadvertently create a process instance that never completes, since each time the process finish rule is executed, an instance of the activity in the ‘name’ parameter will be created. This behavior is by design and developers may need to cater for this behavior in the Process End Rule code.

Considerations

  • When a process instance is in ‘Running’ status, it means that K2 server is busy executing code for the specific process instance. It is NOT possible to intercept the executing code, or to manage the process instance while it is in ‘Running’ status. Therefore, the only statuses supported for managing process instances are ‘Active’, ‘Error’ or ‘Stopped’.