Affect of setWorkflow() on Audit


Details

The setWorkflow() 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.

How does it affect Auditing?

1. Create a new incident record.

2. Check the history of the record by navigating to the History -> List. It shows the state as "New" for update number =0.

3. Run below script in background scripts

var gr=new GlideRecord('incident'); 

gr.get('<give sys_id of the record>'); 

gr.work_note = 'test in background'; 

gr.state=2;

gr.setWorkflow(false); 

gr.update();

4. Delete the history of the record and Reload the incident record once again.

5. Check the Audit history of the same record now.

It shows as if the incident is never created with State: New, and at the time of record creation, the state is set to "In Progress" which is not correct.

Usage of setWorkflow(false) at different levels of record updates give different Audit History results.