- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2009 02:40 PM
I'm using an email notification to send out information regarding approvals on RITM's. The information I want to send will contain the variable information from the item that was ordered.
I stole this script from another email notification:
template.print("Summary of Requested item:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");
template.print(" Options:\n");
for (key in gr.variables) {
var v = gr.variables[key];
if(v.getGlideObject().getQuestion().getLabel() != '' && v.getDisplayValue() != '') {
template.space(4);
template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n");
}
}
}
My only issue is that the variables don't display in the proper order. You would think this would be an easy thing to accomplish, but I've been stuck for awhile. Any ideas?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2010 06:31 AM
Yes, you can put a mail script right into the message. I have this setup on an approval request, here's the details:
table: sysapproval_approver
event: approval.inserted
and then I have a condition on the notification so that it only sends out for RITMs:
Approval for.Number "starts with" RITM
And finally here is my mail script inside the message of the email (this looks a little different than the one I posted, it helped me get the variables in order):
<mail_script>
template.print("Summary of Requested item:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");
template.print(" Options:\n");
var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery("request_item", current.sysapproval);
varown.query();
while (varown.next()){
var visible = varown.sc_item_option.item_option_new.visible_summary;
var question = Packages.com.glideapp.questionset.Question.getQuestion(varown.sc_item_option.item_option_new);
question.setValue(varown.sc_item_option.value);
if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true){
template.space(4);
template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n");
}
}
}
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 10:26 PM
Thanks this was really helpful, for a beginner like myself.
I have used this script and it is working perfectly, except where I have a variable label that displays if a specific selection is made, I would like this to display on the notification.
Is there a way to have the label display in the notification?
template.print(" <b>Request Details:</b>\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() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
template.space(4);
template.print(vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br/>");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 06:14 AM
My guess is that the vs.get(i).getDisplayValue()!='' is evaluating to false (so, there isn't a display value for variable label). I would adjust it to add an "OR" into the condition:
if(vs.get(i).getLabel() != '' && (vs.get(i).getDisplayValue()!='' || vs.get(i).getType() == 11) && vs.get(i).getDisplayValue()!='false')