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

Can you post a screenshot of you task and the script you wrote? Also can you confirm, in the task form, the incident linked has field name as parent?


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

mzmoore
Mega Expert

find_real_file.png

mzmoore
Mega Expert

find_real_file.png

mzmoore
Mega Expert

find_real_file.png

Your script is wrong. You need to use this script

 

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.