- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 06:16 AM
Hi,
I need to get the comments of the approval table when the approval is rejected for a catalog item.
i have created an email script.
The catalog item is Outlook Mailbox Permissions Request.
When an approval is rejected, the comments has to be sent to the requested user.
I have created an event and called that in the workflow to trigger the notification. the comments with which the user is rejecting the request has to be sent via email
Below is the code please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 07:24 AM
event is on which table, notification is on which table?
please share some screenshots.
this will fetch the rejection comments if your notification is on RITM table
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var comment = '';
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.addQuery('state', 'rejected');
gr.query();
if (gr.next()) {
comment = gr.comments.getJournalEntry(1);
}
template.print(comment);
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 07:18 AM - edited 07-02-2025 07:18 AM
Hi @Abdul ,
You will have to query sys_journal_field for comments, try this script
(function runMailScript(current, template, email, email_action, event) {
var comment = '';
var approverGr = new GlideRecord('sysapproval_approver');
approverGr.addQuery('sys_id', current.sys_id); // Replace with Rejected Approval Record Sysid
approverGr.addQuery('state', 'rejected');
approverGr.query();
if (approverGr.next()) {
var journalGr = new GlideRecord('sys_journal_field');
journalGr.addQuery('element_id', approverGr.sys_id);
journalGr.addQuery('element', 'comments');
journalGr.orderByDesc('sys_created_on');
journalGr.query();
if (journalGr.next()) {
comment = journalGr.value;
}
}
if (!comment) {
comment = 'No rejection comments were provided.';
}
template.print("Your request was rejected with the following comment:<br><br>" + comment);
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 07:24 AM
event is on which table, notification is on which table?
please share some screenshots.
this will fetch the rejection comments if your notification is on RITM table
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var comment = '';
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.addQuery('state', 'rejected');
gr.query();
if (gr.next()) {
comment = gr.comments.getJournalEntry(1);
}
template.print(comment);
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 08:01 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader