how to disable options in choice list

sathishk
Mega Contributor

Hello,

We need to disable/unselectable some choices in the state field. In helsinki version we were using 'document.getElementById' to disable the option in the onload client script and is working fine. But when our instance got upgraded to Jakarta it is not working... all the choice list options were selectabe by the users where it should not.

Based on the suggestion provided 'https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-opt... ' I tried to write a new UI script and called that function in onload client script but it is not working.

Can anyone help me in fixing this issue.

The weird part is 'document.getElementById' is working in my personal developer instance which is in Jakarta version.

Regards,

Sathish.K

11 REPLIES 11

Hi Sathish,



Without using DOM manipulation it cannot be disabled. One approach if you want to avoid dom is that onChange of that drop down field show alert that this drop down cannot be selected.



What's the purpose of showing those if they won't be used based on some condition. Use this condition and in onLoad disable those options. This will be the easiest approach.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi Sathish,



Any update on this?



Regards


Ankur


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

Hi Ankur / Chuck,



We get it fixed. They want the fields to be displayed but shouldn't selectable. Two fields with this issue "State" and "Contact Type". Those options will be used when incident created from portal / through integrations but user should not select from incident form.



We disabled the client scripts which using the DOM to hide this options and written a new UI Policy. In the script, we included jQuery and HTML to fulfill this requirement.


Using getAttribute we got the element id and using setAttribute we disabled those options.



Thanks for your suggestions.



-Sathish.K


Community Alums
Not applicable

Sathish,



This is what I am looking for. Can you share the script here?



Thanks,


Rajini


Hi Rajinis,
 
I have a similar kind of requirement. In case you get the solution, could you please share the tech docs for the same. 

Thanks & Regards,
Abhi