Change Request Rejected Comments

Community Alums
Not applicable

Hello! I am attempting to edit the 'change.itil.approver.reject' template to include the name of the approver and the reject comments in the notification to the requester.

 

I created this mail script:

 

<mail_script>

var chRej = new GlideRecord("sysapproval_approver");

chRej.addQuery("sysapproval", current.sys_id);

chRej.query();

while (chRej.next()) {

email.setSubject("Your Change Request has been rejected by" + chRej.approver);

template.print("<b>Comments:</b>" + chRej.comments + "\n");

}

</mail_script>

 

The notification fires when the approval is rejected by email and via the interface, however the variables are not appearing in the email. The comments are blank, and the 'chRej.approver' variable shows up as what looks like a GUID of some sort (i.e f37a9a636f1c210087f8d4e44b3ee4e8). So, I end up with this:

 

---

Subject: Your Change Request has been rejected byf37a9a636f1c210087f8d4e44b3ee4e8

Body:


Comments:

 

 

 

 

Ref:MSG0005012

---

 

Am i not querying the correct table? Any assistance here would be appreciated!

 

Cheers!

1 ACCEPTED SOLUTION

Jake Gillespie
Mega Guru

Hi Tim,



Building on what Donnie said, you can use the getJournalEntry() method to retrieve all comments or specific comments. If you retrieve the latest comment using getJournalEntry(1), the comment will appear with a header (showing a date/time stamp and the user who added the comment, followed by the multi-line comment. If you wish to drop the header and only show the comment, you can use the substring() and indexOf() methods to truncate the comment string and start it from the second line. See below for an example.



<mail_script>


var chRej = new GlideRecord("sysapproval_approver");


chRej.addQuery("sysapproval", current.sys_id);


chRej.query();


while (chRej.next()) {


email.setSubject("Your Change Request has been rejected by" + chRej.approver.getDisplayValue());


var comments = rec.comments.getJournalEntry(1);


template.print("<b>Comments:</b>" + comments + "\n");         // shows full comment entry with header}


template.print("<b>Comments:</b>" + comments.substring(comments.indexOf("\n")+1) + "\n");         // shows comment only with no header


</mail_script>



Regards,


Jake


View solution in original post

7 REPLIES 7

Hi Jake,



                    May be i asked wring question.


                    When app-rover approving through the email notification. If app-rover clicks on "Reject". Is it possible to ask him to enter comments as a mandatory in notification.



Regards,


Harish.


Hi Harish,



Sorry I didn't realise you meant adding comments via email. You cannot simply enforce a mandatory rule via email such as requiring comments within an email approval. At least not in the same way as you would within ServiceNow. Although you can add HTML to email notifications, you cannot run javascript in the recipient's email client, and this would be necessary for enforcing a mandatory rule in the same way as if the user was using the approval form itself.



It is possible through some careful planning and scripting, to create a process via the Inbound Email Rule, which checks for comments on an email approval/rejection reply. If no comments have been added, it would trigger the email to be sent out again (with a message reminding the approver that they are required to enter a comment to enable the approval decision to be processed. This would be cumbersome and prone to errors where the email could be sent back and forth many times simply because the recipient does not understand the request, or simply adds the comments in the wrong place.



I would recommend a simpler approach, whereby the email provides a link to the approval record within ServiceNow, and from here you could add the necessary form validation rules (e.g mandatory comments).



Regards,


Jake