This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice This article is not considered official documentation for K2 software and is provided “as is” with no warranties.

Objective

How to use the GoToActivity method of the Workflow Management API to move a process instance to a different activity.

Before You Begin

The K2 Five developers reference documentation has examples and information on the API: Developer Reference.

How-to Steps

Example code for an API call to use GoToActiviy:

SCConnectionStringBuilder builder = new SCConnectionStringBuilder();
builder.Integrated = true; //use the current user"s security credentials
builder.IsPrimaryLogin = true; //true = re-authenticate user, false = use cached security credentials
builder.Authenticate = true; //whether to authenticate the user's credentials against the security provider, usually true
builder.Host = k2Server2; //the name of the K2 server
builder.Port = 5555; //you must use port 5555 when connecting with the management API
builder.SecurityLabelName = "K2"; //this sample uses the Active Directory security provider 
K2MgmtServer.Open(builder.ToString());
K2MgmtServer.GotoActivity(ProcessInstanceId, "Task");

The line of importance is: K2MgmtServer.GotoActivity(ProcessInstanceId, "Task"); 

The API makes a call to K2 and utilizes the system name of an activity. In K2 Designer, the display name of an activity may be modified, but the corresponding system name is untouched. For instance a default user task will have the system name of "Task." A second added user task will have the display name of "Task 1".

When using the API call, be sure to reference the desired activity by the system name. To verify the system name of the activity you are looking for, the following database query can be run.  This query takes the workflow display name and returns the matching display and system name for the workflow's activities.

Declare @Workflow NCHAR(50)
Set @Workflow ='Workflow DisplayName Goes Here'
SELECT [DisplayName], [Name] AS 'System Name' FROM [K2].[Server].[Act] WHERE ProcID = (SELECT ProcVerID From [K2].[Server].[ProcSet] Where [DisplayName]= @Workflow)