Copy comments from RITM to Task & vice versa.

Naveen87
Tera Guru

Hey Experts,

I'm trying in PDI, I want to fetch additional comments & work notes from RITM to Task & vice-versa.
Please do suggest a simple script with explanation.

Also on which table(BR should be written) also under BR which table should Glided is still a confusion for me.

Under RITM I dont see worknotes tab.

 

find_real_file.png

Under Task, I dont see addition comments.

Please suggest .

find_real_file.png

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

You can try below

1.  After Insert/Update business rule that runs on RITM table when Comments | changes

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

    var com = "RITM Comments for " + current.number + " : " + current.comments;
    if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task comments')==-1)
{
    var cattaskis = new GlideRecord('sc_task');
    cattaskis.addQuery('request_item', current.sys_id);
    cattaskis.query();
        if (cattaskis.next()) {
           cattaskis.comments= "RITM Comments for " + current.number + " : " + current.comments;
           cattaskis.update();
        }
    }
})(current, previous);

 

2. After Insert/Update business rule that runs on SC Task table when Comments | changes

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

    var com = "Catalog Task Comments for " + current.number + " : " + current.comments;
    if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task comments')>-1)
{
    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);

To make it understand what we do is as below.

1. When comments are copied from RITM to Catalog task we add static text 'RITM comments'. Once done we check it in IF statement for the keyword. So, if keyword has 'RITM comments' & does not have 'Catalog Task' as keyword. Only then we will copy it to Catalog Task's comments field. 

2. So, now when Catalog Task business rule that copies comments to RITM is processed it will check for keyword that has 'Catalog Task comments' & does not have 'RITM comments' thus ensuring the comments are not copied back & forth thus avoiding duplication.

 

'Under RITM I dont see worknotes tab.' - It seems you are checking on Activity stream & not Form layout or design. If you want to add it to activity stream click on the Configure available fields & move the Worknotes from Available to Selected area.

View solution in original post

7 REPLIES 7

Aman Kumar S
Kilo Patron

Hey,

Below article should help:

Sync comments and work notes

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Jaspal Singh
Mega Patron
Mega Patron

You can try below

1.  After Insert/Update business rule that runs on RITM table when Comments | changes

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

    var com = "RITM Comments for " + current.number + " : " + current.comments;
    if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task comments')==-1)
{
    var cattaskis = new GlideRecord('sc_task');
    cattaskis.addQuery('request_item', current.sys_id);
    cattaskis.query();
        if (cattaskis.next()) {
           cattaskis.comments= "RITM Comments for " + current.number + " : " + current.comments;
           cattaskis.update();
        }
    }
})(current, previous);

 

2. After Insert/Update business rule that runs on SC Task table when Comments | changes

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

    var com = "Catalog Task Comments for " + current.number + " : " + current.comments;
    if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task comments')>-1)
{
    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);

To make it understand what we do is as below.

1. When comments are copied from RITM to Catalog task we add static text 'RITM comments'. Once done we check it in IF statement for the keyword. So, if keyword has 'RITM comments' & does not have 'Catalog Task' as keyword. Only then we will copy it to Catalog Task's comments field. 

2. So, now when Catalog Task business rule that copies comments to RITM is processed it will check for keyword that has 'Catalog Task comments' & does not have 'RITM comments' thus ensuring the comments are not copied back & forth thus avoiding duplication.

 

'Under RITM I dont see worknotes tab.' - It seems you are checking on Activity stream & not Form layout or design. If you want to add it to activity stream click on the Configure available fields & move the Worknotes from Available to Selected area.

Thank you Jaspal,

 

I tried below simple script & it worked for me

 

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

	var rec = new GlideRecord('sc_req_item');
rec.addQuery('sys_id', current.request_item.sys_id);
rec.query();
while(rec.next()) {
	//rec.work_notes = 'Work note copied from ' + current.number + ' - ' + current.work_notes.getJournalEntry(1) + current.comments + current.comments.getJournalEntry(1);
// 	rec.work_notes= 'Work note copied from ' + current.number + ' - ' + current.work_notes;
// 	rec.comments=current.comments;
	rec.work_notes= 'Work note copied from ' + current.number + ' - ' + current.work_notes.getJournalEntry(1);
	rec.comments = current.comments.getJournalEntry(1);
	rec.update();
}

})(current, previous);

 

I would like to understand what does this line does?

 

 

 if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task comments')>-1)

 

Also a question, If we right on both RITM & TASK. Won't it get into a loop?

 

 if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task comments')>-1)

Is answer to your question.

Also a question, If we right on both RITM & TASK. Won't it get into a loop? 

So, as to avoid it getting in loop what is being done is we are adding keywords.

So, if a comment is made on RITM we add 'RITM comments' as keyword along with comment made. This will be copie to Catalog task.

When it is copied to Catlaog task to avoid loop i.e. to copy on RITM we do a check with indexOf()>-1

i.e. contains if so do not action & update the comment.