The CreatorCon Call for Content is officially open! Get started here.

Urjent!!! Including the option "None" from the script making it non mandatory in the catalog item form

Bhavana Reddy
Mega Guru

Hello Guys,

We have a variable "SVO" ( Which is select box variable with None) and the we have added below script to add options dynamically based on the value from the other field , The problem here is we need to manually add the options "--None--" in the script to avoid the auto selection of the first option , We have also written a UI Policy to make the field mandatory as below 

find_real_file.png

Onchange client script to dynamically set the Options for SVO field

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var oppr = g_form.getValue('opportunity_id');
var ga = new GlideAjax('QuoteDisplay');
ga.addParam('sysparm_name', 'getQuotedetails');
ga.addParam('sysparm_oppr', oppr);
ga.getXML(populateDetails);

function populateDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answerArray= answer.split(',');
g_form.clearOptions('svo');
g_form.addOption('svo','--None--','--None--');
//g_form.setMandatory('svo');
for(var i=0; i<answerArray.length; i++){
//g_form.addInfoMessage(answerArray[i]);
// g_form.clearOptions('quote_test');
g_form.addOption('svo',answerArray[i],answerArray[i]); // set this field dynamically based on Opportunity ID variable
}
}
}

Please anyone help me how i can make the field mandatory even if its "--None--" 

 

1 ACCEPTED SOLUTION

Hi,

try to add this line after you clear

g_form.addOption('svo',' ','--None--'); // value is empty for None

Regards
Ankur

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

View solution in original post

13 REPLIES 13

My choice setting is based on the value from the other variable "Opportunity" , when you change multiple times the Opportunity then it doesnt show the None option itself and shows only the options set from the script, i want to show "None" everytime the "Opportunity" field is changed.

If you change the addChoice none to:

g_form.addOption('svo','none','--None--');

Does it help?

Nope, it doesnt work

Hi,

you can keep Include None

when the variable changes you can clear the choices using g_form.clearOptions()

at that time None which is OOB won't get removed and will still be shown

Then based on response you can populate new options

Regards
Ankur

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

I tried earlier also as you suggested but it doesnot work, whenever the variable changes the None will be removed

find_real_file.png

Please see above screenshot whenever the "Opportunity ID" is changed the None is cleared...