How to kill the workflow process

  • 26 September 2012
  • 3 replies
  • 3 views

Badge +2

Hi,


We have a requirement wherein if user checks a checkbox, workflow process should end. Can anybody tell me how to achieve this through .net code or do we need to write a line rule that on user selection goes to last step.


We would prefer a .net approach to kill the process.


Thanks,


Abhishek


3 replies

Badge +3

Hi Abhishek


You can use this namespace :


SourceCode.Workflow.Management;


 


First create a connection with management server :


WorkflowManagementServer server = new WorkflowManagementServer();


//Define connection string


SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder myConnStr = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();

                myConnStr.Host = "MyK2ServerName"; //replace
                myConnStr.Authenticate = true;
                myConnStr.Integrated = true;
                myConnStr.IsPrimaryLogin = true;
                myConnStr.EncryptedPassword = false;

                myConnStr.Port = 5555;
                myConnStr.UserID = "User Login with admin rights on K2"; //replace
                myConnStr.WindowsDomain = "Domain name"; //replace
                myConnStr.Password =""; //replace
                myConnStr.SecurityLabelName = "K2";
                myConnStr.AuthData = string.Empty;


//Open connection


server.Open(myConnStr.ToString());


server.DeleteProcessInstances(processID, false); //you have to know process instance ID - 2nd parameter is deleteLogEntries


server.Close();


 


You can also use this method if you want to force your process instance to go to a specific activity :


server.GotoActivity(processID, activityName);


 


 

Badge +8

I would refrain from Deleting the process instance, the GoTo approach is something that gives you a lot more options. Like closing the statuses in your external database, sending closure notifications, etc. in the final activity. Using the SourceCode.Workflow.Management API also requires the account that executes this to have Administrator permissions on the K2 Server, whereas a GoTo only requires the user to have a Worklist item in his/her worklist. 


 


The neatest solution in my opinion would be make this decision part of your outcomes and line rules, routing to a Canceled or Stopped activity. This way it does the same as the GoTo, but it also gives you a graphical representation, compared to the GoTo.

Badge +8

Also note that using the Management API as mentioned above requires that the user running the code have Admin rights on the server (not just the process).

Reply