Copy RITM Worknotes to SCTASK - ServiceNow Support

nameisnani
Mega Sage

Hi Team ,

 

I have to whcih ever we have updated in additonal comments the same should be copied in sctask worknotes only a particular catalog item 

 

I have configured After update BR for 

 

nameisnani_0-1752643152554.png

nameisnani_1-1752643177493.png

 

 

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

    var latestComment = current.comments.getJournalEntry(1); // get latest additional comment

    var taskGr = new GlideRecord('sc_task');
    taskGr.addQuery('request_item', current.sys_id);
    taskGr.query();
    while (taskGr.next()) {
        taskGr.work_notes = "Customer Comment from RITM:\n" + latestComment;
        taskGr.update();
    }

})();

 

Test Reults -

 

nameisnani_2-1752643276730.png

nameisnani_3-1752643308805.png

 

 

comments were not copied ritm to sctask 

 

can any one please help me what was the mistake here .

 

@Ankur Bawiskar  could you pllease help me here on my mistake 

7 REPLIES 7

ritu_saluja
Tera Expert

Hello @nameisnani,

 

Try a before business rule add condition as current.comments.changes()

and try using this script
(function executeRule(current, previous /*null when async*/) {
// Check if the catalog item matches the desired one
if (current.cat_item.name == 'Your Catalog Item Name') {
// Get all open catalog tasks related to this RITM
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.addQuery('state', '!=', 3); // Closed
task.query();
while (task.next()) {
// Copy RITM comments to SCTASK work notes
task.work_notes = 'RITM Comments: ' + current.comments.getJournalEntry(1);
task.update();
}
}
})(current, previous);

Also check the activity  stream in sctask and verify if worknotes field is checked or not

Mark my answer correct and helpful if it helps you

Di Zhang
Tera Guru

I don't see any error in the code.  Can you give us the activity stream screen shot for sctask?  Did you check if the login user has write access to work_notes field in sctask? 

Mark Manders
Mega Patron

I think it should work as soon as you make it a before BR. But also check the activity stream, because you are only showing the 'work notes' field and that will never be filled by automation.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark