- 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-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-12-2015 02:52 PM
Hi Michael,
Thank you so much! I am not too sure what is different between your code and mine however as soon as I turned your mailscript into a mailscipt it worked right away!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2015 02:55 PM
Awesome glad to hear my example code helped. I will admit my code was created prior to Fuji and mail scripts so I hadn't gone down that route yet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2015 03:08 PM
Yeah, I am not used to mail scripts either, but apparently servicenow doesn't like you not using them in some instances so its just easier to create a mail script. But either way, it worked, and I am very thankful
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015 11:37 AM
Hi Michael,
How could I revise your script to only pull one specific variable into an email rather than all of them?
Thanks,
Jason