What happened if I setWorkflow(false)

ammar_k
Tera Contributor

Hello, 

I am running a script background for updating some cases, this triggers a business rule that send mail to users, to prevent that i use the method setWorkflow(false)

should I set the workflow back to true after ? what happened if I don't ? 

 

thank you 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@ammar_k The setWorkflow(false) prevents business rules/flows/workflows from running. It is not needed to set the setWorkflow to true afterwords.

View solution in original post

6 REPLIES 6

Chaitanya ILCR
Kilo Patron

Hi @ammar_k ,

 

it's setWorkflow(false)

should I set the workflow back to true after ? what happened if I don't ? 

since it's a background script that you are running there is no action for you to take

 

 

you can review this below KB to get complete understanding of what setWorkflow(false) does when set it

https://www.servicenow.com/community/developer-articles/demystifying-setworkflow-false-method-its-im...

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Valmik Patil1
Kilo Sage

Hello @Chaitanya ILCR ,

 

Below are some details,

1. What is SetWorkflow(false) :

In ServiceNow, setWorkflow(false) is a method used to suppress business rules and workflows from being triggered when a GlideRecord operation (like insert(), update(), or delete()) is performed.

 

2. Do you need to set it back to true?

No, you don't need to reset it to true. The setWorkflow(false) call only affects that specific GlideRecord instance and only during that transaction. It does not persist or affect other records or future executions.

So you don’t have to worry about something like:

gr.setWorkflow(true); // Not required

Thank,

Valmik Patil

Sandeep Rajput
Tera Patron
Tera Patron

@ammar_k The setWorkflow(false) prevents business rules/flows/workflows from running. It is not needed to set the setWorkflow to true afterwords.

Ankur Bawiskar
Tera Patron
Tera Patron

@ammar_k 

just before the update() method you need to use setWorkflow(false) so that stops business rule, flow, workflows, notifications from triggering

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader