Notifications- To Display Only True Values and Ignore False

rachelturkariga
Giga Contributor

Hello Experts, 

I have a catalog item with check boxes and when ever there is a notification sent for approval i want to checked values to be displayed and ignore false values.

Thank You In advance.

1 ACCEPTED SOLUTION

Hi Rachel,

Can you share what values/checkbox user has selected?

Still not getting why if statements are required; the below script should show only those checkboxes which are selected/true

(function runMailScript(current, template, email, email_action, event) {

var ritmSysId = current.sys_id;
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs = set.getFlatQuestions();

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.print(label + ' : ' + variableValue);

})(current, template, email, email_action, event);

this would print like this

Approve Quotes : True

Read only : True

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

21 REPLIES 21

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

for this you would require email script and include that in email notification; you would require multiple if else statements

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

if (current.variables.<variable_name>.toString() == 'true')
template.print('Read Only Contarts true'); 


})(current, template, email, email_action, event);

Sample script in mail script to have it for all true/false variables; this would work in global scope only

var ritmSysId = current.sys_id;
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs = set.getFlatQuestions();

for (var i=0; i < vs.size(); i++) {

if (vs.getLabel() != "" && vs.getDisplayValue() != "" && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + " " + vs.get(i).getDisplayValue() + "");

}

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

rachelturkariga
Giga Contributor

Hi Ankur,

 

Thank You for your immediate reply,

This is how i add the script right?

I choose the value that is is name field to write the script ?

Please refer screenshots

 

Thank You Again for the quick help.

Hi,

you need to use the name field for script

you can use second script and it would print all those variables which are true

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

rachelturkariga
Giga Contributor

which script do we use the 1st or 2nd