- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2015 10:30 PM
Hi Community,
I am struggling to get an approval email to include the options for the catalog request items.
I found: http://wiki.servicenow.com/?title=Scripting_for_Email_Notifications#Summary_of_Requested_Items
<mail_script>
template.print("Summary of Requested items:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sysapproval);
gr.query();
while(gr.next()) {
var nicePrice = gr.price.toString();
if (nicePrice != ) {
nicePrice = parseFloat(nicePrice);
nicePrice = nicePrice.toFixed(2);
}
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n");
template.print(" Options:\n");
for (key in gr.variables) {
var v = gr.variables[key];
if(v.getGlideObject().getQuestion().getLabel() != '') {
template.space(4);
template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n");
}
}
}
</mail_script>
However, when I try to acctually implement this it is not showing the options like it should
All I get in my email is:
Summary of Requested items:
And no options for my RITM tasks.
It should however look something like:
Summary of Requested item:
RITM0010114: 1 X XXXXXX Account at $0.00 each
Details of this request:
Requestor:
Employee's Name:
Job Title:
Contact Number (Ext.):
Store Number:
Line Manager: C
Please select role:
Nominated Printer:
Authorisation: Yes
Authorisation: Yes
Departments required:
Does anyone have any ideas of what is going wrong in my mail script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2015 02:14 PM
Rob, I have this working in my instance. I basically cloned the code that worked with sc_requests and make it work with sc_req_items:
- Created 3 new event registrations: reqitem.approval.inserted, reqitem.approval.rejected, reqitem.approval.cancelled
- Edited the out of the box business rule called "Approval Events (Task)" that runs on the sysapproval_approver to create one of the above events for approvals on sc_req_item
- Created 3 new email notifications that are called when the 3 above events are fired: Requested Item Approval Request, Requested Item Approval Rejected, Requested Item Approval Cancelled
- Created email templates for each.
I assume you followed similar steps to mine. Below is the code for the template that gets called on new approval requests. I put this into the Email Template Message field, NOT HTML.
Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.request.requested_for}
Requested By: ${sysapproval.request.opened_by}
Total Price: ${sysapproval.request.price}
<hr/>
<mail_script>
template.print("Summary of the Request:\n");
var nicePrice = current.sysapproval.price.toString();
if (nicePrice != '') {
nicePrice = parseFloat(nicePrice);
nicePrice = nicePrice.toFixed(2);
}
template.print(current.sysapproval.number + ": " + current.sysapproval.quantity + " X " + current.sysapproval.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n");
template.print(" Options:\n");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
}
}
</mail_script>
Comments:
${sysapproval.description}
<hr/>
${mailto:mailto.approval}
<hr/>
${mailto:mailto.rejection}
<hr/>
Click here to view Approval Request: ${URI}
Click here to view ${sysapproval.sys_class_name}: ${sysapproval.URI}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2015 10:47 PM
I hope you are writing the above script without "<mail_script> </mail_script>" in a "Notification Email Script" and then calling it using "${mail_script:script name}" in your email body.
Create mail scripts in System Policy > Email > Notification Email Script starting with the Eureka release. Then add a ${mail_script:script name} embedded script tag to the body of the email notification or template, replacing script name with the name of the script you created.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2015 10:53 PM
Don't embed it directly into the Email Notification body. That won't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2015 03:28 PM
hi Tanaji,
Yes i am using a mail script i just copied the code as it was from the site to explain. But this still isn't working and pulling the values from the RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2015 08:57 PM
Hi Rob,
We did it slightly different and created a field called Order Details and then used the post from Jace to populate that field with all the details and in the correct order etc.
Jace Benson posted this and it is amazing. We use it for Catalog Approvals and to show the customer what they actually ordered without all the blank fields etc.
Show Catalog Variables as if they were on the form