Skip to main content
Nintex Community Menu Bar
Solved

Is it possible to stop and delete a Workflow instance or to short close using Store Procedure

  • December 16, 2022
  • 3 replies
  • 313 views

Forum|alt.badge.img+3

Hi All,

I have requirement to stop & Delete or shortclose an active workflow using a stored procedure.

Just wondering, is there any approach to achieve this ?

 

Appreciate your response! 

Best answer by sng

You can run this query to check for running instances:

 

SELECT *
FROM [Server].[ProcInst]
WHERE [Status]=1

 

To stop the running instance, you can run the following Update query:

UPDATE [Server].[ProcInst]
SET [Status] = 4
WHERE [Status] = 1  AND ID = <ProcInstID> 

 

You may need to pass in an ID or Folio name to filter the instances according to your requirements to stop an active workflow.

 

You can use the following stored procedure to remove instances:

exec [Server].kProcInstRemove @ProcInstID=ProcInstId],@ServerID=0,@LogData=0x0,@ExpireOnDelete=1


exec [Serverlog].lProcInstRemove @ProcInstID=[ProcInstId]

 

3 replies

Forum|alt.badge.img+3
  • Nintex Employee
  • Answer
  • December 20, 2022

You can run this query to check for running instances:

 

SELECT *
FROM [Server].[ProcInst]
WHERE [Status]=1

 

To stop the running instance, you can run the following Update query:

UPDATE [Server].[ProcInst]
SET [Status] = 4
WHERE [Status] = 1  AND ID = <ProcInstID> 

 

You may need to pass in an ID or Folio name to filter the instances according to your requirements to stop an active workflow.

 

You can use the following stored procedure to remove instances:

exec [Server].kProcInstRemove @ProcInstID=ProcInstId],@ServerID=0,@LogData=0x0,@ExpireOnDelete=1


exec [Serverlog].lProcInstRemove @ProcInstID=[ProcInstId]

 


Forum|alt.badge.img+3
  • Author
  • Rookie
  • December 20, 2022

This worked perfect, thank you so much for your help! But just asking out of curiosity, are we allowed to touch K2 DB and use SPs ? I mean does it cause any issue with Nintex K2 Support.


Forum|alt.badge.img+9
  • Rookie
  • December 23, 2022

You are 100% correct - you should never run stored procedures against the database from your own code / solutions - this will potentially leave you in an unsupported state.

You should either use the management portal to do this, or if this is required as part of a process then you should design you process in such a way that it has an outcome on the relevant task(s) that allows the WF to be complete by calling that outcome in the process itself.  This will not however delete the process, only complete it.

It would also be possible to create a custom ServiceBroker or an Endpoints Assembly  that uses the SourceCode.Workflow.Management API - the WorkflowManagementServer class has both a StopProcessInstance and DeleteProcessInstance methods.  Have a look here for some examples from that API (but not those two specific methods)

 

Cheers