how to add comments made while rejecting the approval in RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 12:03 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 04:15 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2023 02:19 PM - edited ‎08-29-2023 12:49 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 02:03 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 05:23 AM
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);