- Business Rule - How to generate an automatic approval message when an approver approves via email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 11:16 AM - edited 03-08-2023 11:38 AM
Hello, I want to update this business rule to generate an automatic approval message (saying "RITM### has been approved by 'approver'" ) when the approver approves a RITM request via an email without adding in any comments in the response. For example:
(function executeRule(current, previous /*null when async*/ ) {
gs.info('Mj08 Inside BR');
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
if (gr.next()) {
var commentsfull = current.comments.getJournalEntry(1);
if (current.approval_source == 'email') {
var commentswithoutref = commentsfull.substring(0, commentsfull.indexOf('Ref:MSG'));
gs.log("//test//" + commentswithoutref);
gr.comments = commentswithoutref;
} else
{
gr.comments = commentsfull;
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', gr.sys_id);
appr.addEncodedQuery('state=approved^NQstate=rejected');
appr.query();
if (appr.next()) {
var approverName = current.approver.getDisplayValue();
}
gr.comments = gr.number + " has been approved by " + approverName;
}
gr.update();
}
})(current, previous);
My current script generates a blank message:
Can someone please help me?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 11:55 AM
Hi,
Sorry, your post is a bit confusing as you say: "when the approver approves a RITM request via an email without adding in any comments in the response"...
So are you saying you want to leave a comment in the RITM that the record has been approved and then in your notification to the requested user that their request has been approved, you want to see that last comment in the notification? Where you're trying to show who it was approved by?
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 02:56 PM
Hi Allen,
Sorry for the confusion. I want to leave an automatic comment in the RITM approval notification, being sent out to the requested user, when their request gets approved. Most of the times, the designated approver does not include a message when they approve/reject RITM requests via an email response. So when the user receives the email, it's just a blank message.
BUT if the designated approver remembers to include a comment in the email approval, the requested user see's the below example:
I want my script to populate an automatic message when the designated approver does not include a comment in the email approval.
I hope this helps clarifying my original post and not cause more confusion.