How to cancel all running workflows except the newest via a business rule?

Zod
Giga Guru

Hi,

we have a process in place, that will trigger a workflow for each new user ... . This WF contains multiple steps and pauses for some weeks from time to time.

But if something happens "field value change on the table" via a business rule, the currently running workflow should be cancelled (it will restart again anyhow from new) ....

Any coding help here to be added to the business rule to cancel all open workflows ("name abc" for user "sys_id") ?

Thank you!!!

6 REPLIES 6

Chuck Tomasi
Tera Patron

I'm not quite clear on the details on this one. What does this part mean?



This WF contains multiple multiple


This almost sounds like a design issue if you are starting workflows that need to later be canceled. Why run them if that's the case? Closer analysis of the process is required here to make a good judgement. I'm reluctant to create a technical solution (script) without further understanding of the process as it could put you in a bad position later.



I recommend taking a look at the process and trying to determine if you can use the system as it is intended - start a workflow, let it run and do it's various steps and end 'naturally'.


I chuck, corrected 😉 .. thanks.



Things change ... so the user has to do certain things and will be reminded from time to time. If he doesn't - it will be escalated.


But it happens, that the circumstances changes - for example he receives a homeoffice in the meantime .. so he additionally has to do something and the process might be different and therefore needs to be cancelled.


Not nice - but real world. Don't see a change to avoid this ... but also will not put to much effort in it, as this will only happen seldom. Nevertheless   any inappropriate escalation should be avoided ... therefore the initial wf has to be stopped somehow ... . Sure this somehow could be done via complex conditions, but as they are to complex it would be much easier to cancel the wf as soon it is clear, that the old will not be valid anymore ...  


You could have a BR or first activity in the workflow check to see if other workflows are running and cancel those. There are methods in the Workflow API to do that.



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_Workflow_Workflow


divya mishra
Tera Guru

You can use setworkflow as false.