The CreatorCon Call for Content is officially open! Get started here.

how to add comments made while rejecting the approval in RITM

Vijayenthiran S
Tera Contributor

When a request is rejected by the approver, he/she put a comment/reason as to why this request was rejected. i want to copy that comment and paste it to the RITM so that the requestor should know why their request was rejected.

8 REPLIES 8

Hi,

 

Can you try below updated code and make insert checkbox false

(function executeRule(current, previous /*, displayValue, etc.*/) {
    // Check if the approval task was rejected
    if (current.state == 3 /*Rejected*/) {
        var rejectionComment = current.comments.getJournalEntry(-1); // Get the latest comment

        // Get the corresponding RITM
        var ritmGR = new GlideRecord('sc_req_item');
        if (ritmGR.get('sys_id', current.sysapproval)) {
            // Update the RITM with the rejection comment
            var ritmComments = ritmGR.comments.getJournalEntry(-1); // Get existing comments
            ritmComments += "\nRejection Comment: " + rejectionComment; // Append the new comment
            ritmGR.comments = ritmComments; // Update the comments array
            ritmGR.update();
        }
    }
})(current, previous);

Hello @Chaitanya Redd1 

 

The updated script is also not working. The only change is that the state of the RITM changes to Request approved as soon as the request is submitted. Previously, it was Requested for approval.

 

 

Hi @Chaitanya Redd1,

 

Maybe can you help me with a script that copies everything in the comments section when it got updated from sysapproval table to the RITM table.

Hi,

 

Create BR 

  • Set the "Table" to "sysapproval_approver."
  • Choose an "Advanced" condition to specify when this rule should run. For example, you can use a condition like current.comments.changes() to trigger the rule when the comments field is updated.



 

(function executeRule(current, previous /*null when async*/) {
    // Check if the comments field has changed
    if (current.comments.changes()) {
        // Fetch the related RITM record
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get('sys_id', current.parent)) {
            // Copy comments from sysapproval to RITM
            ritm.comments = current.comments;
            ritm.update();
        }
    }
})(current, previous);