- 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-20-2015 11:57 AM
Jason,
To pull a specific field you should be able to just do it inline using something like Field Label: ${current.variables.my_field}
-Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015 12:08 PM
It's a sysapproval email, and it wont pull like that unfortunately. I also tried ${sysapproval.current.variables.my_field}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015 12:12 PM
Try: ${sysapproval.variables.my_field}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015 12:16 PM
Wow I feel silly. Thanks Michael. You're my hero for the day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015 12:19 PM
No worries. Just to confirm variables in the script:
current = sysapproval_approval record
sysapproval = task record requiring approvals
If the record requiring approval is NOT a task, then there are document ID fields that store the table and SysID of the record requiring approval.
With using ${sysapproval.XXX} you can dot walk to anything from the task table.