Catalog Item select box, value of -- None -- ???

will_smith
Mega Guru

Below is my script for a quick test catalog item. I am trying to stop the catalog item from submitting if the Default App is set to "-- None --", but I can't figure out how to check for that value. can anyone help me figure out what value -- None -- holds in a select box? Is it null, undefined, or empty? And, aren't all of those options picked up by .nil?

For the following snippet, I have tried the following combinations to get app to be checked. None of these are working for me.

- (!app)

- (app.nil())

- JSUtils.nil(app)

//Only if the company is empty and they checked more than value of count the order is cancelled. otherwise pass it through

if ((!app) && (numTrue > count || numTrue === 0)) {

answer = false;

} else {

answer = true;

}

////////// FULL SCRIPT BELOW \\\\\\\\\\\\\\\\\\\

//Client Requirement: If they pick more than 1, we want to know which one is their default. And we'll have them type it in, if they haven't already. If default company is filled in - then proceed.

function onSubmit(){

//Set the mandatory checkbox variable names and total mandatory count here

var mandatoryVars = 'reader,lotus,ppt,visio';

var mandatoryCount = 1;

var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);

if(!passed){

//Abort the submit

g_form.showFieldMsg('app_default','Please type in your default company.','error');

field='app_default';

var fieldToFocus = g_form.getControl(field);

fieldToFocus.focus();

return false;

}

}

function forceMandatoryCheckboxes(mandatory, count){

//Split the mandatory variable names into an array

mandatory = mandatory.split(',');

var answer = false;

var varFound = false;

var numTrue = 0;

var app = g_form.getValue('app_default');

//Check each variable in the array

for(x=0;x<mandatory.length;x++){

//Check to see if variable exists

if(g_form.getControl(mandatory[x])){

varFound = true;

//Check to see if variable is set to 'true'

if(g_form.getValue(mandatory[x]) == 'true'){

numTrue ++;

//Exit the loop if we have reached required number of 'true'

if(numTrue > count){

answer = true;

break;

}

}

}

}

alert('You selected ' + numTrue + ' options.');

alert('You chose a default company of ' + app);

//Only if the company is empty and they checked more than value of count the order is cancelled. otherwise pass it through

if ((!app) && (numTrue > count || numTrue === 0)) {

answer = false;

} else {

answer = true;

}

alert('Final answer is ' + answer);

return answer;

}

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi William,



None for select box will hold the blank value. Sample script


var state = g_form.getValue('state'); //assuming state is the name of the catalog variable


alert(state);


if(state == '')


{


alert('1');


}


View solution in original post

10 REPLIES 10

Hi William,



Did you see my response in earlier thread. Select box with none will return the blank value ("")


Please let us know if you have any questions.