Copying RITM worknotes and comments to TASK are generating duplicate comments on RITM activity

nisha29
Kilo Contributor

Hi Team,

Could you please help me to remove Task work_notes and comments from RITM Activity.

Here is my business rule 

written on Before Update

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

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

gr.query();
while(gr.next())
{
//gr.comments = current.comments;
gr.work_notes = current.work_notes;
gr.comments = current.comments;

gr.update();

}
// Add your code here

})(current, previous);

find_real_file.png

7 REPLIES 7

Chase Stevenson
Mega Guru

Do you have a business rule on sc_task table that is copying comments from task to the parent RITM?

It's difficult to tell what is happening in your activity log screenshot, you typed 'test' in work notes of the RITM (from what I assume). And this wrote 'test' on TASK0080746? Then TASK0080746 wrote 'test' back onto the RITM?

Elijah Aromola
Mega Sage

If it is adding duplicate comments, you need to add code that checks if it already exists on that record.

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

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

gr.query();
while (gr.next()) {
    //gr.comments = current.comments;
    if(gr.comments.getJournalEntry(1).indexOf(current.comments) == -1 && gr.work_notes.getJournalEntry(1).indexOf(current.work_notes) == -1) {
        gr.work_notes = current.work_notes;
        gr.comments = current.comments;
        gr.update();

    }

}
// Add your code here

})(current, previous);

Please mark this as helpful/correct if it answered your question!

Prateek kumar
Mega Sage

It should be an after update Business rule.


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

nisha29
Kilo Contributor

@Elijah Aromola thanks for the inputs but it is still reflecting in RITM activity.

Business rule is on Before - Update on SC_REQ_ITEM table.

whenever I am updating any comments and worknotes on RITM its copying into the tasks that's is working fine but it is also reflecting multiple times on the RITM's activity due to which multiple notification are getting trigger, which should not happen.

RITM Activity bringing comments and worknotes of task too .

 

find_real_file.png

find_real_file.png

find_real_file.png