Delete Process Instance Via Stored Proc/SQL

rated by 0 users
Answered (Verified) This post has 1 verified answer | 5 Replies | 1 Follower

Top 25 Contributor
272 Posts
Points 904
tbyrne posted on Fri, Jan 22 2010 8:43 AM

I'd like to write a SQL script that cleans up all of our data and then any related K2 process instances.  Up until know, I've been running the SQL script to clear our data, then going to the workspace to delete process instances (this is for cleaning up development, nothing production-quality).  I'd like to make this a one step process by doing the process instance deletes in SQL - is there a stored proc somewhere in the K2 server to do delete by process instance Id?  Even if it is not recommended to use the stored proc, I don't mind as it is only for development.

Tim Byrne Clarity Consulting http://www.claritycon.com
  • | Post Points: 7

All Replies

Top 500 Contributor
17 Posts
Points 69
Abrn99 replied on Tue, Jan 26 2010 12:28 PM

Hi, i hope below function would help you, since cleaning process instance is available via APIs why you need stored proc.

-------------------------------------------------------------------------------------------------------------------------------------------

public bool

ClearProcessesInstances()

{

 

 

bool deleted = false

;

 

 

try

{

ConnectMng();

SourceCode.Workflow.Management.

 

ProcessInstances items = workflowServer.GetProcessInstancesAll("", "", ""

);

 

 

 

// ManagedWorkListItem managedItem = null;

 

 

foreach (SourceCode.Workflow.Management.ProcessInstance item in

items)

{

deleted = workflowServer.DeleteProcessInstances(item.ID,

 

true

);

}

}

 

 

catch (WFManagedClientContractException

ex)

{

 

 

throw

ex;

}

 

 

catch (Exception

ex)

{

 

 

//...ToDo.

 

 

throw new WFEngineException(ErrorCode

.ErrorImportingManagedList, ex);

}

 

 

finally

{

 

 

// close the connection

CloseMng();

 

 

//workflowServer.Connection.Close();

}

 

 

 

return

deleted;

}

Regards, Abeer Naffa'

The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.

  • | Post Points: 4
Top 25 Contributor
272 Posts
Points 904
tbyrne replied on Tue, Jan 26 2010 12:44 PM

Close, though these queries specifically exclude 'Active' process instances.  Just need to figure out how to clear them even if they are active (simply removing the where status <> '3' doesn't do the trick).  Thanks for pointing me in a direction

Tim Byrne Clarity Consulting http://www.claritycon.com
  • | Post Points: 1
Top 25 Contributor
272 Posts
Points 904
tbyrne replied on Tue, Jan 26 2010 12:44 PM

Sadly, I'd really like to do it in a SQL script so I can clear all of our data and K2 data in one step.

Tim Byrne Clarity Consulting http://www.claritycon.com
  • | Post Points: 1
Top 25 Contributor
272 Posts
Points 904
tbyrne replied on Wed, Jan 27 2010 10:40 AM

Thanks for the help, everyone!  I posted my ultimate solution in my blog:  http://blogs.claritycon.com/blogs/tim_byrne/archive/2010/01/27/stumbling-through-clearing-test-k2-data.aspx

Tim Byrne Clarity Consulting http://www.claritycon.com
  • | Post Points: 1
Page 1 of 1 (6 items) | RSS