What is the use of setWorkFlow(false)? Scoped GlideRecord - setWorkflow(Boolean enable) Enables or disables the running of business rules, script engines, and audit.

mayanknayak
Tera Contributor

If setWorkFlow(false) disable all business rule run after it. Then why we create those business rule which runs after it.

6 REPLIES 6

Mike Patel
Tera Sage

setWorkFlow(false) basically helps you when you are doing some data changes.

Example:

By default duration field on task is empty and not calculated when task is closed. If want to update that field with actual duration I'll do below;

 That way I updated all tasks but didn't fire any business rule.

var gr = new GlideRecord("task");
gr.addEncodedQuery('active=false^calendar_durationISEMPTY');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
	var gdt1 = new GlideDateTime(gr.sys_created_on.getDisplayValue());
	var gdt2 = new GlideDateTime(gr.closed_at.getDisplayValue());
	var dur = gs.calDateDiff(gdt1, gdt2, false);
	gr.calendar_duration = dur;
	gr.setWorkflow(false); 
	gr.update();
}

work note not updating after setting workflow false

Hi dkboss,

 

Field changes wont be audited, if we use the parameter as "false". 

By default, for all the business rules it will be "setWorkFlow(true)", when we use the false, no field changes or. work notes will be seen under Activity logs.

Click Helpful, if i was able to fulfill the answer.

 

Thanks,

Arjun.

Sumedh Kharode1
Kilo Expert

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.

 

Regards

Sumedh Kharode

www.dxsherpa.com