Need to get the value of the rejection comments

Abdul
Tera Contributor

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

(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.toString();
    }

    template.print(comment);

})(current, template, email, email_action, event);
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Abdul 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Mohammad Danis1
Giga Guru

Hi @Abdul ,

You will not be able to access comment field from "sysapproval_approver" table as the comments are available in sys_journal_field table.

In application navigator you can search sys_journal_field.list and press enter, it will give all the comments in the system

Go to approver and find the table and sys_id of the record.

Paste the sys_id of the record in the element_id of the sys_journal_field. You will get your comments.

 

Modify your email script accordingly.

GlideFather
Tera Patron

Olá @Abdul
and how do you set the approval - via flow?
If so, you can get the condition in the action that rejection will add a comment to the form and each comment triggers automatically email to the requestor...

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


i am using a workflow how can i do it there?

in the action step where are you setting the approval to be "approved" or "rejected", add there a comment and it shall then trigger the OOTB notification like any other comment was added...

Something like [If] [Approval] [Rejected], add a comment "Your request was Rejected by ${approval.approver}", something like this

 

EDIT: and you wanted the comment to be retrieved, so:  "Your request was Rejected by ${approval.approver}, with justification: ${approval.approval_for.comment}".

I don't remember the fields for the exact dot-walking, it is just an idea and it must be adjusted correctly.

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */