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

Hello.

 

I have updated the script. Please use the below script in the business rule it will work. I have tested it on my PDI.

 

 

(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.getJournalEntry(1);
           ritmis.update();
        }
    
})(current, previous);

 

@Saurav11 

 

I have one more request ,

 

If i have update comments in RITM also the same should refelect in SCTASK also 

 

How to do that 

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.

 

Aman Kumar S
Kilo Patron

Hi @nameisnani ,

You will need to create a After Update business rule on the SC Task table, with condition as Additional comments changes

 


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

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

    ritm_gr.update();

}

 

Best Regards
Aman Kumar

Hi @nameisnani ,

Did you try this script?

 

Best Regards
Aman Kumar