- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 01:31 PM
I created a notification, if approver rejects the approval the submitter will get the notification. The notification is working fine but approver provides rejection comments those comments are not showing in the email.
We are using approval engine for the approver workflow. We wrote a mail script that show comments in the notification but it seems not working.
Below is the code for that:
/*var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("document_id", current.sys_id);
gr.query();
if (gr.next()) {
var comment = gr.comments.getJournalEntry(-1);
var comm = comment.split("\n\n");
template.print(comm[0] + "\n");
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:46 PM
Hi @Yamja ,
Please use the below updated script,
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("document_id", current.sys_id);
gr.addQuery("state=rejected"); // filter rejected approval recod only for the given document_id
gr.query();
if (gr.next()) {
var comment = gr.comments.getJournalEntry(-1);
var comm = comment.split("\n\n");
template.print(comm[0] + "\n");
}
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 12:31 AM
Hello @Yamja ,
Please give a try to the script below and see how it works for you.
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("document_id", current.sys_id);
gr.addQuery("state", "rejected");
gr.orderByDesc("sys_created_on");
gr.setLimit(1); // Limit the result to the latest rejection record
gr.query();
if (gr.next()) {
var comment = gr.comments.getJournalEntry(-1);
var comm = comment.split("\n\n");
// Extract additional information from the rejection record, e.g., approver's name, rejection date, etc.
var approverName = gr.approver.getDisplayValue(); // Change 'approver' to the correct field name
// Assuming 'template' is an instance of 'GlideEmailOutbound', you can use the 'addBodyText' method
template.addBodyText("The approval request has been rejected by " + approverName + ".\n");
template.addBodyText("Rejection Comment: " + comm[0] + "\n");
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:46 PM
Hi @Yamja ,
Please use the below updated script,
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("document_id", current.sys_id);
gr.addQuery("state=rejected"); // filter rejected approval recod only for the given document_id
gr.query();
if (gr.next()) {
var comment = gr.comments.getJournalEntry(-1);
var comm = comment.split("\n\n");
template.print(comm[0] + "\n");
}
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 01:38 PM
Is there any way we can show those comments in our custom table(Form) notes.
If that possible that would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 01:54 PM
yes , you can copy the rejected comment to the record ( RITM ).
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("document_id", current.sys_id);
gr.addQuery("state=rejected"); // filter rejected approval recod only for the given document_id
gr.query();
if (gr.next()) {
var comment = gr.comments.getJournalEntry(-1);
var comm = comment.split("\n\n");
current.sys_id.comments = comm[0]; // set the comment to current.sys_id record which is rejected
template.print(comm[0] + "\n");
}
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 12:31 AM
Hello @Yamja ,
Please give a try to the script below and see how it works for you.
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("document_id", current.sys_id);
gr.addQuery("state", "rejected");
gr.orderByDesc("sys_created_on");
gr.setLimit(1); // Limit the result to the latest rejection record
gr.query();
if (gr.next()) {
var comment = gr.comments.getJournalEntry(-1);
var comm = comment.split("\n\n");
// Extract additional information from the rejection record, e.g., approver's name, rejection date, etc.
var approverName = gr.approver.getDisplayValue(); // Change 'approver' to the correct field name
// Assuming 'template' is an instance of 'GlideEmailOutbound', you can use the 'addBodyText' method
template.addBodyText("The approval request has been rejected by " + approverName + ".\n");
template.addBodyText("Rejection Comment: " + comm[0] + "\n");
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket