How to hide Choice options without removing them

ritaaudi
Tera Contributor

Hi: I want to be able to hide some Choice entries but not remove them, so that they can be updated by business rules but prevent the user from selecting them. Is there a way to do this? I know you can use g_form.removeOption(<field>, <choice>). I guess I am looking for a g_form.hideOption(<field>, <choice>), but that doesn't work.

Thanks for your help!

Rita

1 ACCEPTED SOLUTION

Sure Rita.



Just to give you another option-


"g_form.removeOption(<field>, <choice>) did not work for me because when I set the removed choice using the business rule, the removed choice did not appear on the form."


To show the removed choice when it is set by business rule you can add condition to the onLoad client script/UI action(containing removeOption()) to check if the current choice is not the one to be removed and if it not then remove the option.


For e.g. lets say you don't want to allow the users to select state1.


Then you can add condition - State is not state1 - and in script 'g_form.removeOption('state','state1');'.


This will remove the option only if it is not currently set on the record. If its set then it will be displayed else it will be removed. If you again set it to any other state again it will be removed.



--Mark correct/helpful if it helps solving your issue.


View solution in original post

12 REPLIES 12

amlanpal
Kilo Sage

Hi Rita,



Hope the following will help you.


Please type 'sys_choice.LIST' in the left naviagtion bar. It will open the Choice table. The filter the conditions by providing required Table name and Element name. The result will show the list of choices. You can then set 'Inactive' field as 'False' of the unwanted choices.



Please mark helpful/correct based on impact


Hello Rita,



g_form.removeOption(<field>, <choice>)


This will just remove the required option from the form and not from the database. If you will reload the form you can see the option again.


So you can write on onLoad client script to remove the required option which will never show that option to users. But you can use that option/set it through the your BRs.



I guess this all what you need.



If you will inactive the choices then you can't use those in your BRs as well.



But if you need that option to be disable on the form and not removed then you can check out below link-


http://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-opti...



Here Mark has provided a UI Script which you can use.


Note: This might not work in Chrome browser.



Thanks,


Tanaji Patil



--Mark correct/helpful if it helps solving your issue.


Hi guys:


I do not want to inactivate the choice as it is still usable.


g_form.removeOption(<field>, <choice>) did not work for me because when I set the removed choice using the business rule, the removed choice did not appear on the form. I wanted it to display on the form but be unselectable by the client.


What worked for me was to have an alert in a client script so if the user selects the wrong choice, they get the alert and are prompted to select another choice. I will try the disabled option, but the alert seems to do the trick.


Regards, Rita


Sure Rita.



Just to give you another option-


"g_form.removeOption(<field>, <choice>) did not work for me because when I set the removed choice using the business rule, the removed choice did not appear on the form."


To show the removed choice when it is set by business rule you can add condition to the onLoad client script/UI action(containing removeOption()) to check if the current choice is not the one to be removed and if it not then remove the option.


For e.g. lets say you don't want to allow the users to select state1.


Then you can add condition - State is not state1 - and in script 'g_form.removeOption('state','state1');'.


This will remove the option only if it is not currently set on the record. If its set then it will be displayed else it will be removed. If you again set it to any other state again it will be removed.



--Mark correct/helpful if it helps solving your issue.