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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sathish,



If you want to remove the choices on form load then why not use g_form.removeOption() method.


g_form.removeOption(<fieldName>, <choiceValue>);



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

Chuck Tomasi
Tera Patron

I'll come right out and say it... DOM manipulation is bad. It's the #1 problem when doing upgrades. Sorry you had to learn this the hard way. It is well documented in the Technical Best Practices.



I recommend you use the g_form.removeOption() method.



Docs: Client Scripts


Docs: GlideForm


Developer: Client Scripting Technical Best Practices Overview


Hi Chuck,



Thanks for your reply.


Yes, we are avoiding DOM objects in our scripts. Previous developers were using that. Need some alternate solution to disable the choices in the state field.



g_form.removeOption() won't work in my case. Choices should be visible and not selectable as shown here. For Eg: New and Canceled should be visible in the options but should not be selectable.



find_real_file.png



-Sathish.K


This is not a function ServiceNow has direct control over using the g_form.removeOption() method.



How the disabled/removed options are presented in the choice list is up to the browser. I know some remove the option entirely while some (IE?) simply gray it out and make it unselectable.



As a customer and Technical Consultant who has done dozens of implementations, I found that "missing" options were not a big concern to users. They are OK only seeing what they can select at a certain point in the process.