Notification email script for variable on a specific catalog item

Vengeful
Mega Sage

Hello everyone,
Anyone can help me about Notification email script for variable on a specific catalog item?
Also, only the TRUE variables from that requested item show up in an approval notification.

 

I have this script, but this is for all catalog items.

 

template.print(' Details:<br />');
var keys = [];
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval.sys_id);
set.load();
var vs = set.getFlatQuestions();
template.space(4);
template.print(' ' + 'Title: ' + " = " +current.sysapproval.variables.u_requested_for.title+ '<br />');
template.space(4);
template.print(' ' + 'Department: ' + " = " +(current.sysapproval.variables.u_requested_for.department).getDisplayValue()+ '<br />');
template.space(4);
template.print(' ' + 'Country: ' + " = " +current.sysapproval.variables.location.country+ '<br />');
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() + '<br />');
}
}

 

I want this to a specific catalog item and displays true variables only.

2 ACCEPTED SOLUTIONS

@Vengeful 

like this

template.print(' Details:<br />');
var keys = [];
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval.sys_id);
set.load();
var vs = set.getFlatQuestions();
template.space(4);
template.print(' ' + 'Title: ' + " = " +current.sysapproval.variables.u_requested_for.title+ '<br />');
template.space(4);
template.print(' ' + 'Department: ' + " = " +(current.sysapproval.variables.u_requested_for.department).getDisplayValue()+ '<br />');
template.space(4);
template.print(' ' + 'Country: ' + " = " +current.sysapproval.variables.location.country+ '<br />');
for (var i = 0; i < vs.size(); i++) {
var label = vs.get(i).getLabel();
var variableName = vs.get(i).getName();
var variableValue = vs.get(i).getDisplayValue();

gs.info(variableValue + " name is " + variableName);
if(label !='' && variableName !='' && variableValue.toString() == 'true')
template.space(4);
template.print((label + ' : ' + variableValue) + '<br />');
}(current, template, email, email_action, event);

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

I already fix it. Remove the all template.space(4); to the script.

View solution in original post

20 REPLIES 20

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Vengeful 

Greetings!

by true variables, you mean variables which are not blank? 

if so, You have to check before each variable then print if variable is not blank or false.

something like 

if(current.sysapproval.variables.location.country != '');

{

template.print(' ' + 'Title: ' + " = " +current.sysapproval.variables.u_requested_for.title+ '<br />');

}

Help others to find a correct solution by marking the appropriate response as correct answer and helpful!!

Kind Regards,

Ravi Chandra.

 

Hi @Ravi Chandra_K ,

Thank you for reply.

What I mean is this. Only the TRUE variables should be displays on the Approval notification.

Merza_0-1688625788915.png

 

Hello @Vengeful 

You can try getDisplayValue() == 'true' 

something like

if(current.sysapproval.variables.u_lot_status.getDisplayValue() == 'true' )

use log statements to verify what you are getting.

please hit the Thumb Icon and mark as Correct based on the impact!!

Regards,

Ravi Chandra.

Hi @Ravi Chandra_K 

How can I make it to a specific catalog item?