Comments Updated In SCTASK , should reflect in RITM also

nameisnani
Mega Sage

Hi,

 

We have requirement that 

 

When we updated comments in SCTASK , the same should be reflect in RITM also .

 

How to implement this requirement.

 

Please provide me implementation steps

 

@Saurav11 @kamlesh kjmar @Community Alums @Gunjan Kiratkar   

1 ACCEPTED SOLUTION

Please do the below:-

 

Create a after insert/update BR on sc_req_item table as below:-

 

Saurav11_0-1669782571160.png

 

Write the below code in the script:-

 

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

updateTasks();

function updateTasks() {
var compare,task_comment2,task_comment,ritm_comment2,ritm_comment;
ritm_comment =current.comments.getJournalEntry(1);

//Remove timestamp and name from additional comment
var regex= new RegExp('\n');
var i = ritm_comment.search(regex);
if (i>0)
{
ritm_comment2 = ritm_comment.substring(i+1, ritm_comment.length);
}

var ritm_gr = new GlideRecord('sc_task');
ritm_gr.addQuery('request_item', current.sys_id);
ritm_gr.query();

if(ritm_gr.next())
{
task_comment =ritm_gr.comments.getJournalEntry(1);

//Remove timestamp and name from additional comment
var i1 = task_comment.search(regex);
if(i1 > 0)
{
task_comment2 = task_comment.substring(i1+1, task_comment.length);
}
compare = ritm_comment2.indexOf(task_comment2);

if(compare == -1) // If No match found
{
ritm_gr.comments = ritm_comment2.trim();
ritm_gr.update();
}
}
}
})(current, previous);

 

 

Then  Wriye an after insert/update BR on sc_task table as below.:-

 

Saurav11_1-1669782664435.png

 

I think you already have created the BR for sc_task table with the above condition. So just update the code to below:-

 

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

// Add your code here

var compare,task_comment2,task_comment,ritm_comment2,ritm_comment;
task_comment =current.comments.getJournalEntry(1);

//Remove timestamp and name from additional comment
var regex= new RegExp('\n');
var i = task_comment.search(regex);
if (i>0)
{
task_comment2 = task_comment.substring(i+1, task_comment.length);
}

var ritm_gr = new GlideRecord('sc_req_item');
ritm_gr.addQuery('sys_id', current.parent);
ritm_gr.query();

if(ritm_gr.next())
{
ritm_comment =ritm_gr.comments.getJournalEntry(1);

//Remove timestamp and name from additional comment
var i1 = ritm_comment.search(regex);
if(i1 > 0)
{
ritm_comment2 = ritm_comment.substring(i1+1, ritm_comment.length);
}
compare = task_comment2.indexOf(ritm_comment2);

if(compare == -1) // If No match found
{
ritm_gr.comments = task_comment2.trim();
ritm_gr.update();
}
}

})(current, previous);

 

Please mark my answer as correct based on Impact.

 

View solution in original post

9 REPLIES 9

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please write an After Insert/Update business rule that runs on SC Task table with condition comments changes

 

(function executeRule(current, previous /*null when async*/ ) {
    var ritmis= new GlideRecord('sc_req_item');
    ritmis.addQuery('sys_id', current.request_item);
    ritmis.query();
        if (ritmis.next()) {
           ritmis.comments= "Catalog Task Comments for " + current.number + " : " + current.comments;
           ritmis.update();
        }
    
})(current, previous);

 

Please check below articles for more information:-

 

https://www.servicenow.com/community/developer-forum/copy-comments-from-ritm-to-task-vice-versa/m-p/...

 

https://www.servicenow.com/community/it-service-management-articles/copy-additional-comments-from-ri...

 

Please mark my answer as correct based on Impact.

Go to Business rule and create a new one with the below screenshot condition:-

 

Saurav11_0-1669779474747.png

 

And then copy paste the script  which I had mentioned earlier in the script part:-

 

Saurav11_1-1669779556383.png

 

Please mark my answer as correct based on Impact.

 

@Saurav11 

SunilKumarPadh_0-1669780567468.png

SunilKumarPadh_1-1669781061601.pngSunilKumarPadh_2-1669781094952.png

 

 

Why comments are not updating . please tell where i need to change