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,

But i still see False Values

Below is the modified script :

(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++) {

if (vs.getLabel() != "APT None" && vs.getDisplayValue() != " none" && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + "APT None" + vs.get(i).getDisplayValue() + "none");
}
else if(vs.getLabel() != "APT Create/Edit Contract" && vs.getDisplayValue() != " create_edit_contact" && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + "APT Create/Edit Contract" + vs.get(i).getDisplayValue() + "create_edit_contact");
}

else if(vs.getLabel() != "APT Review/ Approve Contract" && vs.getDisplayValue() != " review_approve_contact" && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + " APT Review/ Approve Contract" + vs.get(i).getDisplayValue() + "review_approve_contact");
}
else if(vs.getLabel() != "APT Read Only Contract" && vs.getDisplayValue() != "read_only_contarcts" && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + "APT Read Only Contract" + vs.get(i).getDisplayValue() + " read_only_contarcts");
}
else if(vs.getLabel() != "Apttus Lock User" && vs.getDisplayValue() != "lock_user " && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + "Apttus Lock User" + vs.get(i).getDisplayValue() + "lock_user");
}
else if(vs.getLabel() != "Apptus Unlock User" && vs.getDisplayValue() != "appttus_unlock_user" && vs.getDisplayValue()== 'true' ) {
template.print(vs.get(i).getLabel() + "Apptus Unlock User" + vs.get(i).getDisplayValue() + " appttus_unlock_user");

}}

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

Hi,

small mistake in my script;

instead of vs.getDisplayValue() == 'true'

use vs.get(i).getDisplayValue() == 'true'

instead of vs.getLabel() use vs.get(i).getLabel() 

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

Please check and let me know if i need to add or missed anything.

 

rachelturkariga
Giga Contributor

Hi Ankur,

 

I some how see the false values still. Please see the attached screenshot of Notification after test and also  scripts changes made according to your suggestion.

 

Thank You 

Hi Rachel,

Are you iterating over each variable of type checkbox?

gs.info('Question Text: '+ vs.get(i).getLabel()); // this would give you variable text

gs.info('Question Name: ' + vs.get(i).getName()); // this would give you variable name

gs.info('Question Value: '+ vs.get(i).getDisplayValue()); // this would give you that variable value

(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