- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Good Afternoon from Pakistan
Guys, I need your help, I have a requirement to send the approval email notification to all approvers listed in the RITM, when the approver approve the RITM, with the information of Requested for
Can anyone please guide me or provide me the solution that will be really helpfull for me
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
(function executeRule(current, previous) {
// ======================================================
// HARD GUARD – run once per approval
// ======================================================
if (previous.state == 'approved')
return;
if (!current.state.changesTo('approved'))
return;
var ritmId = current.sysapproval;
if (!ritmId)
return;
var ritm = new GlideRecord('sc_req_item');
if (!ritm.get(ritmId))
return;
// Only specific catalog item
if (ritm.cat_item.name != 'Access/Installation for Existing Application/Software')
return;
// ======================================================
// Collect UNIQUE recipients
// ======================================================
var recipients = {};
var recipientList = [];
// 1️⃣ Approver who approved
if (current.approver) {
var approvedBy = current.approver.toString();
recipients[approvedBy] = true;
}
// 2️⃣ Remaining requested approvers
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', ritmId);
appr.addQuery('state', 'requested');
appr.query();
while (appr.next()) {
if (!appr.approver)
continue;
var approverId = appr.approver.toString();
if (recipients[approverId])
continue;
recipients[approverId] = true;
}
// Convert object → comma-separated list
for (var id in recipients) {
recipientList.push(id);
}
if (recipientList.length === 0)
return;
// ======================================================
// Fire ONE event
// ======================================================
gs.eventQueue(
'auto.approval',
current,
recipientList.join(','), // parm1 → ALL recipients
current.approver.toString()
);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @AbdulrehmanT,
Try adding these steps in your flow after any of the approver approved the RITM
-
Query approvers: Use "Look up Records" step to get all approvers for the RITM
-
Loop through approvers: Use "For Each" step
-
Send email: Use "Send Email" action with:
-
To: Current approver's email
-
Subject: "RITM Approval Notification - [RITM Number]"
-
Body: Include:
-
Requested For:
[requested_for] -
RITM Number:
[number] -
RITM Description:
[short_description] -
Approved By:
[approved_by]
-
-
Modify Fields according to your requirement, let me know if you need further help
------------------------------------------------------------------------------------------------------------------------------------------------
Please mark my response helpful and accept as solution
Thanks & Regards
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for your response but this approach I cant use..................
I have created a email notification on sys_approval table
I have created a event registery on sys_approval table
I have created a business rule on sc_req_item.LIST
RUN WHEN: item is laptop and approval state changes to approved
than in the advanced script im using the below code,
(function executeRule(current, previous) {
// // Safety check
// if (!current.sysapproval)
// return;
// Collect all approvers for this RITM
var recipients = [];
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', current.sys_id);
appr.query();
while (appr.next()) {
if (appr.approver) {
recipients.push(appr.approver.toString());
}
}
// Fire event with approver list
gs.eventQueue(
'auto.approval',
current,
recipients.join(','), // parm1 = all approver sys_ids
current.approver.toString() // parm2 = approver who approved
);
})(current, previous);
the above code is not working,..............it should send the approval email to all approvers listed in the approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I don't think sc_req_item where u run this business rule has approver field, can u check this part and confirm
Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes @AbdulrehmanT,
current.approver.toString() is not available on the RITM table, if you want the name of the approver who approved that particular request you need to find that record on 'sysapproval_approver' table conditions will be Current RITM and state of that approval should be approved (because rest of them goes into 'No Longer Required State' if you set the rule to Anyone approves or Reject)
So, add this logic in your script and if you need help do let me know
-----------------------------------------------------------------------------------------------------------------------------
Please mark my response helpful and accept as solution
Thanks & Regards
Mayank
