Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Approval Record comments to copy to Parent RITM

Tfnhodgi
Tera Contributor

I know there are multiple threads on this but I have had no luck. For example add Website to whitelist. This RITM will go to 4 Security people where only one needs to approve. If they reject or simply add a comment we want that comment to copy to the Parent RITM. I have looked at many threads and all are not working for me. 

Business rule 

Table - Approval [sysapproval_approver]

When to run- Before / on Update /  filter - I have it set to Comments changes. 

My current Script-  Not sure how close this is to working

(function executeRule(current, previous /*null when async*/) {
 
    var grRITM = new GlideRecord('sc_req_item');
    if(grRITM.get(current.sysapproval)) {
    grRITM.comments = "Comment copied from approval record:\n\n" + current.comments;
    grRITM.update();
}
})(current, previous);

 

 

1 ACCEPTED SOLUTION

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Tfnhodgi 

 

you can write before business rule  and use the below Script:

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

    // Add your code here
    // Get the parent RITM (Request Item)
    var reqitem = new GlideRecord('sc_req_item');
    reqitem.addQuery('sys_id', current.document_id);
    reqitem.query();
    if (reqitem.next()) {
        reqitem.comments = reqitem.comments + "\n" + current.comments.getJournalEntry(-1); 
        reqitem.update(); 
    }

})(current, previous);

 

It is working in my pdi

Thanks and Regards

Sai Venkatesh

View solution in original post

9 REPLIES 9

Alex Rose
Tera Guru

Hi @Tfnhodgi ,
You'll need to get the approval's comment from the sys_journal_field table:

var journalGR = new GlideRecord('sys_journal_field');
journalGR.addQuery('element_id', current.getUniqueValue());
journalGR.addQuery('element', 'comments');
journalGR.query();

if(journalGR.next())
    grRITM.comments = journalGR.value;

 

tried with no luck.

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Tfnhodgi 

 

you can write before business rule  and use the below Script:

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

    // Add your code here
    // Get the parent RITM (Request Item)
    var reqitem = new GlideRecord('sc_req_item');
    reqitem.addQuery('sys_id', current.document_id);
    reqitem.query();
    if (reqitem.next()) {
        reqitem.comments = reqitem.comments + "\n" + current.comments.getJournalEntry(-1); 
        reqitem.update(); 
    }

})(current, previous);

 

It is working in my pdi

Thanks and Regards

Sai Venkatesh

Hi, this is not working. I add the comment (below screenshot) and I want it to go the Parent RITM but it is not. Is there anything else that can block this?

Tfnhodgi_0-1718222562685.png