mail script not working in workflow notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2019 02:23 PM
Hello,
I have been using a mail script in an approval email that sucks up all of the variables on an RITM and spits them out in an email. This has been working in the approval email, but now I am trying to use it in a workflow notification and it is failing. I was hoping someone might be able to provide some insight as to why. Here is the script I am using.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id",current.sc_req_item );
item.query();
while(item.next()) {
var fields = item.getFields(); //gets the name and values of all the fields the query returns
//gs.log(item.getAttribute('name') + " EPO approval mail script");
gs.log('Enumerating over all fields with values:');
for (var m = 0; m < fields.size(); m++) {
var glideElement = fields.get(m);
}
gs.print('');
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '' && vs.get(i).getValue()!='') {
if(vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue().toString() != 'false')
{
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
}
}
}
}
})(current, template, email, email_action, event);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2019 03:53 PM
Hi Maverick,
Thank you for linking that, unfortunately that is not where my problem is occurring. I am doing this via an event and a notification, but the email is coming out blank because the mail script is failing. I was hoping someone could help spot check me where I went wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2019 04:00 PM
Hello,
Unfortunately, your post is confusing. First you say you're doing this in a workflow notification. Now you're saying it's an event and a notification.
Which is it?
Side note, you also have: gs.print(''); in there and that's only for background scripts to console, etc.
So if it's hitting that it may cause it not to successfully complete.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2019 06:44 PM
you need to change the below statement
item.addQuery("sys_id",current.sc_req_item );
to
item.addQuery("sys_id",current.sys_id);