Unable to terminate a workflow from API

  • 27 November 2017
  • 2 replies
  • 12 views

I am trying to terminate a running workflow instance using the following piece of code from C# project.

 

WorkflowManagementServer server = new WorkflowManagementServer();
//Define connection string
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder myConnStr = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();

myConnStr.Host = "K2 Application Server Name"; //replace
myConnStr.Authenticate = true;
myConnStr.Integrated = true;
myConnStr.IsPrimaryLogin = true;
myConnStr.EncryptedPassword = false;

myConnStr.Port = 5555;
myConnStr.UserID = "admin user id"; //replace
myConnStr.WindowsDomain = "domain"; //replace
myConnStr.Password = "password"; //replace
//myConnStr.SecurityLabelName = string.Empty;
myConnStr.AuthData = string.Empty;
//Open connection
server.Open(myConnStr.ToString());
//server.StopProcessInstances(277);
server.DeleteProcessInstances(449,true); //you have to know process instance ID - 2nd parameter is deleteLogEntries}

 

Each time, I run this, I am getting the blow given error

“User K2:xxxx does not have administrator permissions"

 

I tried using the service account using which this was installed, and also using the account under which K2 Black Pearl Service is running. Still the same error.

 

What am I missing here?

 

Thanks in Advance.


2 replies

Userlevel 5
Badge +18

Sometimes if a process instance is stuck in a Running state, it may not be possible to stop the process instance via the API or UI available.  However, it can be stopped via database manipulation as per:


 


http://community.k2.com/t5/tkb/articleprintpage/tkb-id/TKB_blackpearl/article-id/3388


* As this involve a database edit, please backup the database prior to implementation


 

Badge +9

Hello Upendra,

 

 

As Tim Said, Running instances can't be deleted using API or UI until they are stopped before doing so. So in your code uncomment this line //server.StopProcessInstances(277); and try again. If it didn't work alternatively you can try using goto Activity set it to End activit of the workflow and then try deleting the instance. Code to use for Goto is below

 

K2.GotoActivity("<END Activity Name>")

 

Check these options and let us know if it works.

 

Regards,

Vijay.

Reply