Adding approval email and name as a comment on RITM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2024 03:54 AM
Hi Team
i created async BR with condition as addition of comment is equal to false and with below code
(function executeRule(current, previous /*null when async*/ ) {
// Wait for 2 minutes
//gs.sleep(120000); // Delay for 2 minutes
var seconds = parseInt(120, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while (start > parseInt(new Date().getTime())) {
// do nothing
}
// Retrieve the associated RITM
var ritmSysId = current.sysapproval.sys_id;
// Collect all approver details
var approvalGr = new GlideRecord('sysapproval_approver');
approvalGr.addQuery('sysapproval', ritmSysId); // Match approvals related to the RITM
approvalGr.addQuery('u_addition_of_comment', false); // Only unprocessed records
approvalGr.query();
var individualApprovals = [];
while (approvalGr.next()) {
if (approvalGr.approver) {
// Individual-level approval
individualApprovals.push(approvalGr.approver.getDisplayValue() + ' (' + approvalGr.approver.email + ')');
}
// Mark the approval as processed
approvalGr.u_addition_of_comment = true;
approvalGr.update();
}
// var groupapproval = new GlideRecord('sysapproval_group');
// if (groupapproval.get(ritmSysId)) {
// // Construct the consolidated comment
// var comment = '';
// if (individualApprovals.length > 0) {
// comment += 'Your service request is currently awaiting approval from the group. To proceed, it requires approval from one of the designated approvers listed below: \n' + individualApprovals.join(',\n') + '\n';
// }
// } else {
// Construct the consolidated comment
var comment = '';
if (individualApprovals.length > 0) {
comment += 'Your service request is currently awaiting approval from\n' + individualApprovals.join(',\n') + '\n';
}
//}
// Update the RITM with the consolidated comment
if (comment) {
var ritmGr = new GlideRecord('sc_req_item');
//ritmGr.addQuery('sys_id',ritmSysId);
if (ritmGr.get(ritmSysId)) {
var lastcomment = ritmGr.comment.getJournalEntry(1);
if (lastcomment != comment) {
ritmGr.comments = comment; // Add the comment to the RITM
ritmGr.update();
}
}
}
})(current, previous);
but it is working first time when group of approval triggered updating only in one comment with all the list of approval and it is not working for next time it is updating comment with 'n' times as per 'n' approval records creation
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2024 04:21 AM
What are the Filter conditions on the When to run tab? Is there a Condition on the Advanced tab?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2024 04:50 AM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2024 05:14 AM
I'd build this in flow designer instead.
Easier to articulate, and WAY easier to walk through each transaction.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 09:58 PM
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark