Solved

Need ideas/starting point - Cancelling Old Workflow instances

  • 22 January 2020
  • 2 replies
  • 14 views

Badge +10

We have a heavily used solution. In order to reduce long running instances, we defined a business process (identify long running instances, give user chance to extend, backup of application data and flag request as cancelled at application level i.e. setting status as cancelled in application tables).

 

For the most part this process is automated but I have not been able to automate the cancellation of workflow instances. Currently, I cancel instances manually one by one. I wish to automate this part as well. The cancellation process is built in Powershell, I don't know Visual studio. Is it possible to call Management API in Powershell to cancel? What other options I have besides Visual Studio?

 

Thanks

icon

Best answer by boringNerd1 22 January 2020, 04:41

View original

2 replies

Badge +15

Hi,


 


You can use the Management API with Powershell. It's just a little tricky, since loading the assemblies into Powershell can be a little tedious. I have to follow this method to load the assemblies required.


 


I have uploaded an example of a simple Powershell script I have created that stops a process instance. This doesn't include any exception handling, so if you want to use them, you will have to make some modifications to it. You will need to copy the SourceCode.HostClientAPI.dll and SourceCode.Workflow.Management.dll into the tm folder, then execute test.ps1.


 


Refer to tm.psm1 in the tm folder for the exact Powershell commands that are used.


 


SourceCode.HostClientAPI.dll can be found in [Program Files]K2Host ServerBin on your K2 server.


SourceCode.Workflow.Management.dll can be found in [Program Files]K2Bin on your K2 server.


 

Badge +10
Thank you sir. Script worked great. Thanks for taking time to help me out.

Reply