Email Template not working as intended

amacqueen
Mega Guru

I have constructed a new user request order guide and there is one issue that isn't working for me. When I generate an email to the approver of the request using the request.itil.approve.role template the email received does not fully populate. The 'Requested For' field is blank and both the 'Summary of Requested items' and the 'Comments' fields are also blank. I can't work out where I am going wrong so would appreciate some assistance in working it out.

See below for the content of the email template:-

Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.requested_for}
Requested By: ${sysapproval.opened_by}
Total Price: ${sysapproval.price}




template.print("Summary of Requested items:\n");
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();
while(item.next()) {
var nicePrice = item.price.toString();
if (nicePrice != '') {
nicePrice = parseFloat(nicePrice);
nicePrice = nicePrice.toFixed(2);
}
template.print(item.number + ": " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n");
template.print(" Options:\n");

var keys = new Array();
var set = new Packages.com.glideapp.servicecatalog.variables.VariablePoolQuestionSet();
set.setRequestID(item.sys_id);
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");
}
}
}

Comments:
${sysapproval.description}


${mailto:mailto.approval}


${mailto:mailto.rejection}


Click here to view Approval Request: ${URI}
Click here to view ${sysapproval.sys_class_name}: ${sysapproval.URI}

Thanks to anyone that can assist.
2 REPLIES 2

Kiwipedro
Mega Contributor

Hi Angus,

This template is called on the Approval table which has the sysapproval reference field on it. This refers to the request table (sc_request).

Check under the "Approvals" list of records and select an approval that is pending. Have a look at the "Approval For" field. That should show a request number. The field in the email template is "dot-walking" to this table and then returning the requested_for value. If you aren't using requests in this fashion (I recommend you do - see my comments in your other post) then that's why you're not getting a value in the notification.

This will also explain the issue with your request item list. If there is no "parent" request number then the query item.addQuery("request", current.sysapproval); will not return any records.

The comments are also coming from the request table, from the "description" field.

Thanks
Peter


I was having the same problem with the ${sysapproval.requested_for} not working in a notification and found the following to work:



Requested For: ${sysapproval.request.requested_for}