Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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  ||  10x 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

@Vengeful 

you are already handling this in your email script

if(label !='' && variableName !='' && variableValue.toString() == 'true')

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

Hi @Ankur Bawiskar ,

I'm not sure if I done it right.

Here's the original requested item approval email for all request items.
I exclude the new request item (Cloud Services Internal User Menu Access) here.
Sys ID is not "........"

Merza_0-1688950422865.png

Here's the approval email I created for that specific request item.

Sys ID is "......."

Merza_1-1688950483353.png


Then here's the original notification email script for all requested item

Merza_2-1688951250543.png


Here's the notification email script I created for that specific item.

Merza_3-1688951321611.png

I tried to submit a request and check the email logs.
The approval email still captured the existing notification.

Merza_4-1688951828334.png

 

How can I make the Cloud Item Approval Requested captured to this catalog item: Cloud Services Internal User Menu Access?

@Ankur Bawiskar @Ravi Chandra_K ,

I already fix the notification

Merza_0-1688957737453.png

But the email body is still showing the "false" items

Merza_1-1688957803702.png

 

@Vengeful 

are you sure you are calling the correct email script from email body?

also did you check by adding gs.info()

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

Hi @Ankur Bawiskar 

Here's the email body

Merza_0-1688961322028.png

Can you show how can I add the gs.info()?