setWorkFlow() use?

Shrngika
Tera Expert

can anyone please help me to understand about setworkflow(false) this function with example.

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

Hi please find below

setWorkflow()

The serWorkflow() method accepts one argument: a boolean true/false value. This argument will determine whether business rules should be triggered by any database actions performed by your GlideRecord script. For example, if you make a change and call the update() method, calling setWorkflow() and passing in false will prevent any business rules that would normally be triggered by that update from running.


‘setWorkflow’ is used to enable/disable the running of any business rules that may be triggered by a particular update.

 

//Change the category of all 'software' incidents to 'hardware' without triggering business rules on updated records
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.query();
while(gr.next()){
gr.category = 'hardware';
gr.setWorkflow(false);// this will ensure that there will be no business rule update for this update.
gr.update();
}
Regards
Harish

Any idea on how to prevent this from being used in the system ??

suvro
Mega Sage
Mega Sage

If you trying to modify/create a record in Servicenow using GlideRecord. It may happen that there are some business rules that are written for that modification or on insert of a record. 

For example, You are changing the state of incident to In Progress using GlideRecord. And there is business rule which has a condition that state changes to In Progress. So when you run your script that business rule will also run. There might be many other things also configured like workflow, notifications etc on that condition. 

SO if you do not want your code changes to trigger any other code like Business Rule, Workflow etc 

use setWorkflow(false). This will make sure no other scripts are fired due to the changes your script is doing