Copy comments of approval of a requested item to the comments field of the RITM.

Student1
Tera Contributor

Hello,

I would like once a user comments something on an approval form (for example an approval of a requested item), the comments to be copied to the comment field of the requested item.

I would like to achieve the following:

1) Once the approver opens an approval form, he/she will be able to see all the comments that have been added in the RITM until that time.

2) Once the approver comments on the approval form, the comment to be added on the comments field of the RITM.

For example, on below screen, my user ("AAAA") opens the approval form. However, he is not able to see all the comments that have need added until now on the RITM. Then, we post a comment, this comment must be added to the comments field of the RITM.

find_real_file.pngThank you so much all.

1 ACCEPTED SOLUTION

Hi,

so it is going in loop.

please add this in both the BRs

var updateInitiatedBy = updateInitiatedBy || current.sys_id.toString();

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

    if(updateInitiatedBy != current.sys_id.toString()){   
     return;
    } 

// your code to update

})(current, previous); 

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Please create after update BR on sysapproval_approver table

Condition: Comments Changes AND current.source_table == 'sc_req_item'

Script:

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

    // Add your code here

var ritm = new GlideRecord('sc_req_item');

ritm.get(current.sysapproval);

ritm.comments = current.comments.getJournalEntry(1);

ritm.update();

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar Thanks Ankur. 

I guess the code that you kindly provided copies the approver's comments to RITM comments.

 

How can I make also the other way around? The RITM comments to be copied on the approval's comments.

 

So, when a user opens an approval form, he/she will be able to see all the comments of the RITM until that time.

Hi,

for other way round use this

I assume user has valid READ ACL to see the comments on both the forms

After update BR on sc_req_item table

Condition: Comments changes

Script:

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

    // Add your code here

var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval',current.sys_id);
appr.query();
if(appr.next()){
appr.comments = current.comments.getJournalEntry(1);
appr.update();
}

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hii Ankur,

when approver approve the request and add comments then that comment will be display to only requester(me) and approval. but we want to display that comments to all approver but it is noyt showing .could you give me some  solution for this issue?