Work notes only copied to one task, not all

CarolMa6
Tera Expert

Hi 

My business rule isn’t working as expected. What am I missing? When I add work notes to Task 1, they only update Task 2, but Task 3 doesn’t get any of the notes. It seems to copy notes from Task 1 to Task 2, but Task 3 remains unchanged

 

CarolMa6_0-1764764921998.png

(function executeRule(current, previous /*null when async*/ ) {

    var gr = new GlideRecord("sc_task");
    gr.addQuery("request_item", current.request_item);
    gr.addQuery("number", "!=", current.number);
    gr.query();
    while (gr.next()) {
        gr.work_notes = current.getJournalEntry(1);
        // to disable businesss rules on this record we can use setwrokflow false
        //gr.setworkflow(false);
        gr.update();
    }

})(current, previous);
12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@CarolMa6 

your script is wrong to grab the value from work notes

Also are you sure there are 3 tasks and not 2?

(function executeRule(current, previous /*null when async*/ ) {

    var gr = new GlideRecord("sc_task");
    gr.addQuery("request_item", current.request_item);
    gr.addQuery("number", "!=", current.number);
    gr.query();
    gs.info('Total tasks' + gr.getRowCount());
    while (gr.next()) {
        gr.work_notes = current.work_notes.getJournalEntry(1);
        // to disable businesss rules on this record we can use setwrokflow false
        //gr.setworkflow(false);
        gr.update();
    }

})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Anupam1
Mega Guru

Hi @CarolMa6 ,

 

The trigger conditions are part of the problem — "Work notes changes" + "State is Closed Complete" means the rule only fires when a task is already closed and then gets a note added. That’s not a natural flow, so simplifying to just "Work notes changes" is a good debugging step.

But even if the condition is corrected, the script itself needs adjustment. current.getJournalEntry(1) only returns the latest note, and assigning directly to gr.work_notes overwrites the journal field instead of appending. That’s why only one sibling task gets updated and Task 3 stays unchanged.

 

(function executeRule(current, previous) {

 

    var note = current.getJournalEntry(1); // latest work note

 

    var gr = new GlideRecord("sc_task");

    gr.addQuery("request_item", current.request_item);

    gr.addQuery("number", "!=", current.number);

    gr.query();

 

    while (gr.next()) {

        gr.setWorkflow(false); // prevent other rules from firing

        gr.setJournalEntry("work_notes", note); // append properly

        gr.update();

    }

 

})(current, previous);

 

 

Key fixes:

  • Use setJournalEntry("work_notes", note) instead of gr.work_notes = … so notes append correctly.
  • Keep setWorkflow(false) to avoid recursive triggers.
  • Adjust the condition to "Work notes changes" or "State changes to Closed Complete" depending on your business intent.

This way, all sibling tasks (Task 2, Task 3, etc.) under the same RITM will consistently receive the copied notes.

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Best,

Anupam.

CarolMa6
Tera Expert

@Viraj Hudlikar @Anupam1 @Rampriya-S 

 

The code updates 'Task1' and 'Task2', but 'Task3' only receives work notes from 'Task1' and not from 'Task2'