Cancel task SLA default workflow from business rule:

saddamstarr
Tera Contributor

HI All,

I have a customized business rule from some SLA will get cancelled, But However the cancelled SLA's clock is not stopping, because cancelled SLA's workflow are in stil progress.

So i need to cancel the workflow from my business rule.

Please find the BR rule some code which is not cancelling the SLA workflow:

find_real_file.png

kindly provide your input to how i can change my code to cancel the default sla workflow.

Regards,

Saddam

1 ACCEPTED SOLUTION

Hi Saddam,



In your case current is task_sla record. So please try



var workflow = new Workflow();


workflow.cancel(task_sla_gr);



Also remove the line of code related to task_sla_gr.setWorkflow(false);



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

13 REPLIES 13

Alikutty A
Tera Sage

Hi,



You can cancel a workflow using the following line of code:   new Workflow().cancel(current);



Please refer


https://www.servicenowguru.com/scripting/business-rules-scripting/canceling-executing-workflows-task...


https://wiki.servicenow.com/index.php?title=Workflow_Script#cancel.28record.29



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


oharel
Kilo Sage

Hi Saddam,


setWorkflow(false) is used to skip running business rules during a gliderecord update.


instead try:


var workflow = new Workflow();


workflow.cancel(current);


saddamstarr
Tera Contributor

Thanks Harel & Alikutty



I'm writing business rule on incident table and cancelling sla workflow based on condition.



However i tried with :


var workflow = new Workflow();


workflow.cancel(current);



which is not cancelling the workflow.



kindly suggest.



Regards,


Saddam


Hi Saddam,



In your case current is task_sla record. So please try



var workflow = new Workflow();


workflow.cancel(task_sla_gr);



Also remove the line of code related to task_sla_gr.setWorkflow(false);



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response