Copy task comments and worknotes to parent request item
Import
·
Oct 16, 2020
·
article
The following are business rules we use to copy work notes and comments from the request task to the parent requested item record. Hopefully these will be useful for other folks as well...
//Name: Copy comments from TASK to RITM
//Table: sc_task
//Advanced: true
//When: Before Update; Additional Comments <changes>
//Condition: current.comments.changes() && current.comments.indexOf('Comment added from:') < 0;
// Note that the condition prevents the note from copying multiple times.
//Script:
(function executeRule(current, previous /*null when async*/) {
if(current.comments.nil()){
return;
}
else {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',current.request_item);
gr.query();
while(gr.next()){
gr.comments = "Comment added from: " + current.number + " | " +current.request_item.cat_item.name + "\n >>> " +current.comments;
gr.update();
}
}
})(current, previous);
//Name: Copy work notes from TASK to RITM
//Table: sc_task
//Advanced: true
//When: Before Update; Work Notes <changes>
//Condition: current.work_notes.changes() && current.work_notes.indexOf('Work Note added from:') < 0;
// Note that the condition prevents the note from copying multiple times.
//Script:
(function executeRule(current, previous /*null when async*/) {
if(current.work_notes.nil()){
return;
}
else {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',current.request_item);
gr.query();
while(gr.next()){
gr.work_notes = "Work Note added from: " + current.number + " | " +current.request_item.cat_item.name + "\n >>> " +current.work_notes;
gr.update();
}
}
})(current, previous);
Cheers !
View original source
https://www.servicenow.com/community/now-platform-articles/copy-task-comments-and-worknotes-to-parent-request-item/ta-p/2324086