Trying to use setWorkflow(false) and update work_notes this does not seem to allow journal fields to be updated when false string fields seem to work ok. Does anyone know how to update work_notes without causing BR to fire

eroth
Kilo Contributor

UpdateTasks();

function UpdateTasks() {

      if (current.sys_id == '') {

              return;

      }

      gs.log('Current user ID 1');

      var tasks = new GlideRecord('sc_task');

      tasks.addQuery('parent', current.sys_id);

      tasks.query();

      while (tasks.next()) {

              gs.log('Current user ID 2' + current.comments);

              tasks.close_notes = '8989890';

              tasks.work_notes = '12345';

              tasks.setWorkflow(false);

              tasks.update();

      }

}

13 REPLIES 13

Hi Gurupreet,



In order to avoid this issue, m giving the 'setworkflow' method after the update() activity   like below, i think that's how it should be, but not sure.



inc.update();


inc.setWorkflow(false);   //IMPORTANT: ensures the impending update does not trigger business rules


inc.autoSysFields(false); // IMPORTANT:   ensures the impending update does not modify updated date, updated by, or update count.



What i think is, if i make the workflow false immediately after update, as you explained, it will not trigger the backend business rule once again, which is used to carry the data from these journal fields   to sys_journal_field table.



could you confirm is this fine?


Hi Yogesh,



In above case when the script is executed, corresponding BR on target table will not be fired


i.e setWorkflow(false); will disable firing of BR on target table.


Thanks Pradeep.



is it fine to give it after update() method, like below?   or after BR's will be triggered on the target table before the code reaches setworkflow(false) code in the below snippet?



inc.update();


inc.setWorkflow(false);


inc.autoSysFields(false);



i think this helps only to stop the after BR's if it works. before BR's will anyways be triggered on the target table.


Don't know it will work or not ... Ideally it shouldn't work because ... when update statement execute , by default setWorkflow is true and it will trigger the Business Rules and setWorkflow(false) in later statements should not make any difference.


Gurpreet07
Mega Sage

Okay, Found a thread...have a look


https://community.servicenow.com/message/910536#910536