Trying to exclude false and null values in record producer

Sam Motley
Giga Guru

Hi All, 

 

Sorry if this is super simple but i'm unable to make this work so hoping someone could help. 

I'm trying to exclude false or null values when using the record producer. 

We have radio buttons that if not selected it returns a value false which then comes into the ticket. 

I've been able to get either null values not showing or false not showing but not both. 

 

Script below where you can see my failing script. 

 

var gr_questions = new GlideRecord('item_option_new');
gr_questions.addQuery('sys_id', 'IN', arr_questionSysIds.toString()); //Single call to the table with all variables we are looking for
gr_questions.orderBy('order'); //Order by the order they are on the catalog item form
gr_questions.query();
var description = "";
while (gr_questions.next()) {
var question = gr_questions.getValue('question_text');
var value = producer[gr_questions.getValue('name')].getDisplayValue();
if (value !== "false" && !null)
{ //only get variables with values
description += question + ": " + value + "\n";
}

 

I've also tried if ((value !== "false") || (value !== null))

any assistance would be greatly appreciated 

 

Cheers as always 

1 ACCEPTED SOLUTION

Peter Bodelier
Giga Sage

Hi @Sam Motley 

 

Try this:

var gr_questions = new GlideRecord('item_option_new');
gr_questions.addQuery('sys_id', 'IN', arr_questionSysIds.toString()); //Single call to the table with all variables we are looking for
gr_questions.orderBy('order'); //Order by the order they are on the catalog item form
gr_questions.query();
var description = "";
while (gr_questions.next()) {
var question = gr_questions.getValue('question_text');
var value = producer[gr_questions.getValue('name')].getDisplayValue();
if (value && value != null && value != '')
{ //only get variables with values
description += question + ": " + value + "\n";
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

5 REPLIES 5

Peter Bodelier
Giga Sage

Hi @Sam Motley 

 

Try this:

var gr_questions = new GlideRecord('item_option_new');
gr_questions.addQuery('sys_id', 'IN', arr_questionSysIds.toString()); //Single call to the table with all variables we are looking for
gr_questions.orderBy('order'); //Order by the order they are on the catalog item form
gr_questions.query();
var description = "";
while (gr_questions.next()) {
var question = gr_questions.getValue('question_text');
var value = producer[gr_questions.getValue('name')].getDisplayValue();
if (value && value != null && value != '')
{ //only get variables with values
description += question + ": " + value + "\n";
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

thanks @Peter Bodelier i had to add "false" to the first value condition but other than that worked a treat many thanks! 

regards, sam 

sushantmalsure
Mega Sage
Mega Sage

You can try using JSUtil API's nil() or notNil() 

Prod Doc: https://docs.servicenow.com/en-US/bundle/rome-application-development/page/app-store/dev_portal/API_...

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Samaksh Wani
Giga Sage
Giga Sage

Hello @Sam Motley 

 

Just replace your line with :-

 

if ((value != "false") || (value != null))

 

you have used to equals in your code, it should be one

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh