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

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You can use below script that runs after insert/update & on Change of Comments on RITM table.

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

var ritmapp = new GlideRecord('sysapproval_approver');
ritmapp.addQuery('sysapproval',current.sys_id);
ritmapp.addQuery('state','requested'); //copies only to pending approval records
ritmapp.query();
while(ritmapp.next())
{
ritmapp.comments = current.comments.getJournalEntry(-1); //-1 for latest n 1 for all comments
ritmapp.update();
}
})(current, previous);

Student1
Tera Contributor

@Ankur Bawiskar @Jaspal Singh 

I followed your instructions but the comments are not copied from the RITM to the approval.

find_real_file.png

find_real_file.png

 

Any ideas?? What am I missing here?

Student1
Tera Contributor

For example, I have a requested item that needs two steps of approvals (stage 1 and stage 2).

On stage 1, Abel Tuter comments on approval form before approves the requested item, like shown below.

find_real_file.png

Then, after stage 1 being completed, on stage 2 the user must be able to see all the comments that been added to the previous stage.

However, the user can not see previous comments.

find_real_file.png

Hi,

Did you try checking with admin user if that field is visible or not

Regards
Ankur

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

@Ankur Bawiskar 

I really need your help Ankur, if you could help me on that, I would appreciate it so much, since I have spent many hours without finding a good solution..

The problem is the following:

I have a business rule on sc_req_item table (after insert-update, condition: additional comments changes), where I copy the comments of the requested item to the relative approvals.

I have a business rule on sysapproval_approver table (after update, condition: approvalfor.number starts with RITM and comments changes), where I copy the comments of the approval to the relative RITM.

So, its like I have a two-way relationship between RITM and approval.

The issue is that, when I comment on requested item, then the comment is copied on the approval (because of the first business rule), and the comment returns back to the requested item (because a new comment is added to the approval and the second business rule is triggered too).

 

Is it clear?