Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copy Work notes from Problem task to Problem Record Work notes

Midori_Cakes
Tera Contributor

Hello Everyone. I am trying to create a client script so that when someone updates the work notes for the problem task that it will also put a copy of the work notes on the problem record. Similar to how a parent and child ticket works. How would I go about doing this? Please advise.

Thank you!

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Midori_Cakes 

don't use client script.

you should use after update BR with condition as work notes changes and then copy it to problem

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

Midori_Cakes
Tera Contributor

Thanks for the suggestion. I created it and added this script. Can you please look it over:

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

    // Split Array Of Timestamp & User Details and Work Note
    var wn = current.work_notes.getJournalEntry(1).split("\n");
    // Timestamp & User Details
    var wn_0 = wn[0];
    // Work Note
    var wn_1 = wn[1];
   
    var problem = new GlideRecord("problem");

    if (problem.get(current.parent)) {
        problem.work_notes = "Work Note From Problem Task " + current.number + ":" + "\n\n" + wn_0 + "\n\n" + wn_1;
        problem.update();
    }

})(current, previous);

array0045
Tera Contributor

### 📌 Subject:
Copy Problem Task work notes to Parent Problem record

---

### What I’m Trying to Do:
I want to automatically copy work notes from a Problem Task to its parent Problem, whenever work notes are updated.

---

### 🛠️ What I’ve Tried:
I used a Business Rule with `work_notes.getJournalEntry(1)` to pull the latest entry and update the parent Problem.

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

    // Only proceed if work_notes changed and there's a parent problem
    if (current.work_notes.changes() && current.problem) {
        var problemRec = new GlideRecord('problem');
        if (problemRec.get(current.problem.toString())) {
            // Get the latest journal entry
            var latestNote = current.work_notes.getJournalEntry(1);

            // Format note with task number
            var taskNumber = current.getDisplayValue('number');
            var note = '**Update from Problem Task [' + taskNumber + ']**:\n' + latestNote;

            // Add to parent Problem work notes
            problemRec.work_notes = note;
            problemRec.update();
        }
    }

})(current, previous);