Unable to set '--Please select a value--' in catalog item variable

Rakesh50
Mega Sage

Hi,

We have a catalog item  "Access" and it has a variable called 'Category' select box type. It has couple of choices instead of 'None' we want to use "--Please select a value--" option. I have created onload script and it is working in native view but portal not setting the value.Please check attached screenshots.

Onload Native view

Rakesh50_0-1696935681005.png

onload service portal - by default it is setting to first choice option instead of '"--Please select a value--"

Rakesh50_1-1696935845959.png

 

can anyone suggest me to resolve this issue?

 

Thanks,

Rakesh T

 

1 ACCEPTED SOLUTION

Hi @Rakesh50 

Try this code

g_form.removeOption('category','');
g_form.addOption('category','', '--Please select a value--', 0); //no spaces for second paramter
g_form.setMandatory('category', true);

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

9 REPLIES 9

Make sure you check Include None to true and use below code:

VoonaRohila_0-1696938025685.png

 

g_form.removeOption('category','');
g_form.addOption('category', ' ', '--Please select a value--', 0);
g_form.setMandatory('category', true);

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi @Voona Rohila 

Now it is working for service portal but not in platform view. It is setting to choice option

Rakesh50_0-1696938508388.pngRakesh50_1-1696938544603.png

 

 

Hi @Rakesh50 

Try this code

g_form.removeOption('category','');
g_form.addOption('category','', '--Please select a value--', 0); //no spaces for second paramter
g_form.setMandatory('category', true);

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Anubhav24
Mega Sage
Mega Sage

What about using a default value --Please select a value-- mention it while creating the variable.

hi @Anubhav24 ,

if we can set default value then mandatory is not applying to the field.