mail script not working in workflow notification

chrisn_
Mega Guru

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);

7 REPLIES 7

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.

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!

dvp
Mega Sage
Mega Sage

you need to change the below statement 

item.addQuery("sys_id",current.sc_req_item );

to

item.addQuery("sys_id",current.sys_id);