- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
I have to trigger a notification on demand table when the Approval is Rejected . I configured a notification to achieve this but in the notification i have to dynamically show the comments that was added during the rejection
this comments field is from sysapproval table . due to which i cannot get it fields directly in the field section of the notification . I think i have to write a mail script to get the comments of all the Approvals . Please help me with this!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
You’re right, mail scripts is the right track. See an example of script
(function runMailScript(current, template, email, email_action, event) {
var comments = [];
// Query sysapproval_approver table for this approval record
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id); // link to your RITM/Request/Change
gr.addQuery('state', 'rejected'); // only rejected approvals
gr.orderByDesc('sys_updated_on'); // latest first
gr.query();
while (gr.next()) {
comments.push(gr.comments.toString()); // collect rejection comments
}
if (comments.length > 0) {
template.print('<b>Rejection Comments:</b><br/>');
for (var i = 0; i < comments.length; i++) {
template.print('- ' + comments[i] + '<br/>');
}
} else {
template.print('No rejection comments available.');
}
})(current, template, email, email_action, event);
In your Notification → under the Message HTML/body, insert:
${mail_script:<name_of_mail_script>}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
You’re right, mail scripts is the right track. See an example of script
(function runMailScript(current, template, email, email_action, event) {
var comments = [];
// Query sysapproval_approver table for this approval record
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id); // link to your RITM/Request/Change
gr.addQuery('state', 'rejected'); // only rejected approvals
gr.orderByDesc('sys_updated_on'); // latest first
gr.query();
while (gr.next()) {
comments.push(gr.comments.toString()); // collect rejection comments
}
if (comments.length > 0) {
template.print('<b>Rejection Comments:</b><br/>');
for (var i = 0; i < comments.length; i++) {
template.print('- ' + comments[i] + '<br/>');
}
} else {
template.print('No rejection comments available.');
}
})(current, template, email, email_action, event);
In your Notification → under the Message HTML/body, insert:
${mail_script:<name_of_mail_script>}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
@Rafael Batistot thanks! for the solution