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

inatherese
Kilo Expert

I has an issue with two updates, so my solution was:



setWorkflow(false);


setValue('some_field', 'somevalue');


update();


setWorkflow(true);


work_notes = 'blabla';


update();



This way, the workflow will not run during the first part, and then run during the part where I update the work note. Might not work for everyone, depending in what you want to accomplish, but might be the solution to some


huma
Mega Contributor

It worked like a charm


Rick52
Tera Contributor

I was having the same issue, and was able to work this out. Update the work notes field first, then do a second ".update()" with the "setworkflow(false)". See my script below.

var gr_inc_resolved = new GlideRecord('incident');
gr_inc_resolved.addEncodedQuery(query_inc_resolved);
gr_inc_resolved.query();

while (gr_inc_resolved.next()) {
    gr_inc_resolved.u_state_reason = "QA Verified Successful";
	gr_inc_resolved.work_notes = "Incident is auto closed after 7 days";
	gr_inc_resolved.update();
	gr_inc_resolved.state = 7; // Closed
	gr_inc_resolved.setWorkflow(false);
    gr_inc_resolved.active = false;
    gr_inc_resolved.update();
}

Brijesh10
Tera Guru

Hi @eroth  ,

Setworkflow false restrict update of work-notes field.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0867584#:~:text=The%20behavio....

Please mark itcorrect answer and helpful if it resolve the issue.


Thanks,
Brijesh Sahani