Copy Comments and worknotes from TASK to Incident work notes

mzmoore
Mega Expert

Hi _ looking to copy or push task notes and comments to the incident notes and comments field. I would like the Incident Assigned To person to be able to view the task notes from the incident record without switching back and forth.

I copied a BR and tried to tweak to perform the action I needed, but it's not working. Any help would be greatly appreciated.

This is the br I'm using.

copyCommentsToIncidentWorkNotes();

function copyCommentsToIncidentWorkNotes() {
var commentsChanges = current.comments.changes();
var workNotesChanges = current.work_notes.changes();

var link = new GlideRecord("incident_work_notes_link");
link.addQuery("linked_task", current.sys_id);
link.query();
var ids = [];
while (link.next()) {
if (!link.parent.nil()) {
ids.push(link.parent.toString());
}
if (commentsChanges)
link.comments = current.comments;
if (workNotesChanges)
link.work_notes = current.work_notes;
link.setWorkflow(false);
link.update();
}

var incidentworknotes = new GlideRecord("incident_work_notes");
incidentworknotes.addQuery("sys_id", ids);
incidentworknotes.query();

while (incidentworknotes.next()) {
if (commentsChanges)
incidentworknotes.comments = current.number + ": " + current.comments;
if (workNotesChanges)
incidentworknotes.work_notes = current.number + ": " + current.work_notes;
incidentworknotes.setWorkflow(false);
incidentworknotes.update();
}
}

1 ACCEPTED SOLUTION

No. This script is different. I made few changes to line 8. Use this one.

 

copyCommentsToIncidentWorkNotes();

function copyCommentsToIncidentWorkNotes() {
var commentsChanges = current.comments.changes();
var workNotesChanges = current.work_notes.changes();

var link = new GlideRecord("incident");
link.addQuery("sys_id", current.parent);
link.query();
var ids = [];
if (link.next()) {
if (commentsChanges) 
link.comments = current.comments;
if (workNotesChanges)
link.work_notes = current.work_notes;
link.setWorkflow(false);
link.update();
}

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

11 REPLIES 11

SanjivMeher
Kilo Patron
Kilo Patron

On which field of the task do you have the incident number? is it linked_task? If yes, then the below script should work fine.

copyCommentsToIncidentWorkNotes();

function copyCommentsToIncidentWorkNotes() {
var commentsChanges = current.comments.changes();
var workNotesChanges = current.work_notes.changes();

var link = new GlideRecord("incident");
link.addQuery("linked_task", current.sys_id);
link.query();
var ids = [];
while (link.next()) {
if (commentsChanges) 
link.comments = current.comments;
if (workNotesChanges)
link.work_notes = current.work_notes;
link.setWorkflow(false);
link.update();
}

 


Please mark this response as correct or helpful if it assisted you with your question.

mzmoore
Mega Expert

Thank you so much! The task notes are showing up in the Incident notes, however, the task notes are added to every Incident in the system. How can I copy the notes to only the parent incident? 

Also, the task note shows up twice on the incident record as a duplicate. I'm thinking it's because I'm trying to capture comments and work notes. I think for now, I'd just like to capture the task work notes and not the Task comments.

I really appreciate your help.

Please use this script instead.

copyCommentsToIncidentWorkNotes();

function copyCommentsToIncidentWorkNotes() {
var commentsChanges = current.comments.changes();
var workNotesChanges = current.work_notes.changes();

var link = new GlideRecord("incident");
link.addQuery("sys_id", current.parent);
link.query();
var ids = [];
if (link.next()) {
if (commentsChanges) 
link.comments = current.comments;
if (workNotesChanges)
link.work_notes = current.work_notes;
link.setWorkflow(false);
link.update();
}

Please mark this response as correct or helpful if it assisted you with your question.

mzmoore
Mega Expert

Hi Again -

The last script eliminated duplicated work notes. The task work notes still go to every Incident in the system. 

Any suggestions?

Thank you again.