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

rachelturkariga
Giga Contributor

Hi Ankur,

 

I still see the False Values in notifications.

Attached Screenshots of Code, Email Script- Template and Notification screenshot.

 

Thank you so much 

Hi Rachel,

why you require if else statement here?

the above script would print only those which are having true value

Regards
Ankur

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

(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 != 'APT None'&& variableName != 'none'&&variableValue.toString() =='true') {
template.print(label +'APT None'+variableValue);
}
if(label !='APT Create/Edit Contract'&& variableName !='create_edit_contact'&& variableValue.toString() =='true'){
template.print(label + 'APT Create/Edit Contract'+variableValue);
}

if(label !='APT Review/ Approve Contract'&&variableName !='review_approve_contact'&& variableValue.toString() =='true'){
template.print(label +'APT Review/ Approve Contract'+variableValue);
}

if(label !='APT Read Only Contract'&&variableName !='read_only_contarcts'&& variableValue.toString() =='true'){
template.print(label +'APT Read Only Contract'+variableValue);
}

if(label !='Apttus Lock User'&&variableName !='lock_user'&& variableValue.toString() =='true'){
template.print(label +'Apttus Lock User'+variableValue);
}

if(label !='Apptus Unlock User'&&variableName !='appttus_unlock_user'&& variableValue.toString() =='true'){
template.print(label +'Apptus Unlock User'+variableValue);
}
}

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

This my current script and still see false values.

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