Mail script is not working as expected

Yamja
Tera Guru

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");
}

 
Please some one let me know what is wrong with my code.
 
And also is there anyway the comments they provided in the approval request will populate in out custom table notes.
 
Thanks

 

2 ACCEPTED SOLUTIONS

AshishKM
Kilo Patron
Kilo Patron

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

View solution in original post

Aniket Chavan
Tera Sage
Tera Sage

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

View solution in original post

5 REPLIES 5

Yamja
Tera Guru

Both scripts looks similar I have tried Ashish script, it worked for me. Thank you for the response