Solved

Mass deletion of workflows

  • 7 July 2020
  • 3 replies
  • 211 views

Badge +1

K2 Support has not responded to requests for help (I had hoped K2 support would be better than this).  Regardless, I have to get this working by tomorrow morning.

 

We had a code error in our MSSQL database resulting in creating 75,000 workflows with errors (yes, 75 thousand!!).  I need to delete them as its totally killed our system.  I know I can delete the version and therefore delete the workflows associated with it, but I'll lose the 300+ workflows that are needed and would have to restart them (difficult because there are many approval levels).  Any ideas?

icon

Best answer by tbyrne777 7 July 2020, 15:28

The easiest way would be to write a small little console app or even test project that references the K2 API (SourceCode.HostClientAPI, SourceCode.Workflow.Management). Here is an example that should get you most of the way there:

 

SourceCode.Workflow.Management.WorkflowManagementServer wms = new SourceCode.Workflow.Management.WorkflowManagementServer();

using (wms.CreateConnection())
{
wms.Connection.Open(K2ConnectionStringBuilder.ConnectionString);
foreach (SourceCode.Workflow.Management.ProcessInstance pi in wms.GetProcessInstances())
{
wms.DeleteProcessInstances(pi.ID, true);
}
}

View original

3 replies

Userlevel 4
Badge +8

The easiest way would be to write a small little console app or even test project that references the K2 API (SourceCode.HostClientAPI, SourceCode.Workflow.Management). Here is an example that should get you most of the way there:

 

SourceCode.Workflow.Management.WorkflowManagementServer wms = new SourceCode.Workflow.Management.WorkflowManagementServer();

using (wms.CreateConnection())
{
wms.Connection.Open(K2ConnectionStringBuilder.ConnectionString);
foreach (SourceCode.Workflow.Management.ProcessInstance pi in wms.GetProcessInstances())
{
wms.DeleteProcessInstances(pi.ID, true);
}
}

Badge +1

Thanks, support was able to delete these for us.

Badge +1

And also, Support was a bit slow on this particular request originally, but I have to say they did a great job getting everything back up and running, especially considering this was an error on our side and not with K2.

Reply