How to make options greyed out in a select box variable

narendrareddy3
Tera Contributor

There are five options. 1, 2, 3, 4, and 5 in the select box variable of a catalog item. If I select 3, then it should make the other options non-selectable. Can anyone please help me here with how to achieve it?

6 REPLIES 6

SwarnadeepNandy
Mega Sage

@narendrareddy3 
What exactly do you mean? If you select option 3 the select box should become read-only? Is it?
Just be aware, if you are doing that then if anyone selects option 3 accidentally, they wouldn't have any option to edit it. He/she has to reload the form each time.

Kind Regards,
Swarnadeep Nandy

No, not select box variable, should take action on values in the select box

Hi @narendrareddy3,

 

We cannot make the select box dropdown's readonly, we can make the variables read-only. 

Please have a look at this if it helps.

https://www.servicenow.com/community/developer-forum/make-one-value-in-choice-list-quot-read-only-qu...

Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.

msd93
Kilo Sage

Hi @narendrareddy3 

 

Use below on change catalog client script on the select box.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var selectBoxField = g_form.getControl('sel');
var sel = g_form.getValue('sel')
   //Type appropriate comment here, and begin script below
   if(g_form.getValue('sel') == '1')
   {
  selectBoxField.options[2].disabled = true;
    selectBoxField.options[3].disabled = true;
   }
}
 
I had created selectbox with 3 options and when i select 1 I was able to disable 2 and 3 options as shown in the below screenshots

msd93_0-1694177243958.pngmsd93_1-1694177283542.png

Please mark as helpful if it helps you.