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

Hello @Vengeful 

You have to write separate notification for the catalog item you want. (using when to run conditions and exclude the catalog item from already existing one).

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

Regards,

Ravi Chandra.

Hi @Ravi Chandra_K 

I already have a separate notification for that catalog item.
I want this new created notification email script to be on that catalog item as well so it will affect the existing one.

 

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();
if(label !='' && variableName !='' && variableValue.toString() == 'true')
template.space(4);
template.print((label + ' : ' + variableValue) + '<br />');
}(current, template, email, email_action, event);
 

 

Hello @Vengeful 

include Notification Email script in a notification Message HTML field using this syntax:

${mail_script:scriptName}

refer: https://developer.servicenow.com/dev.do#!/learn/learning-plans/utah/new_to_servicenow/app_store_lear...

 

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

Regards,

Ravi Chandra.

Ankur Bawiskar
Tera Patron
Tera Patron

@Vengeful 

what's the exact issue?

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

Hi @Ankur Bawiskar ,

My concern is that on a specific catalog item, only the true variable should be seen by the approver from the email notification.

Example:
Based on this notification, approvers only want the 'true' value or only the requested access they want their email to have. Eliminate the false.

This is only for the new catalog item: Cloud Services

Merza_0-1688716991844.png

Merza_1-1688717010716.png