Hiding certain choices in Select Box Variable Set

carlm1984
Mega Contributor

Hello All,

Wondering if anyone could help with with the best way to try this.


Currently on one of my catalogue items I have a Select Box variable with 20 options in it (Sample below)

find_real_file.png

What I would like to do is add another Select Box Variable which basically lists out by function, e.g. IT, Finance, Procurement.

So if a user select 'Procurement' only the 'Procurement' options show in the approval select box.

Is this achievable?

If so can anyone help, as I can use UI policy's but I don't think in this instance it will work due to the different options and not being able to hide certain items in the approval box.

Kind Regards

Carl

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Carl,



You should be able to do this via Catalog client script i.e using addOption or removeOption. Reference section 6 here.


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0


Thank you for coming back to me Pradeep.



I thought a script might be the way to go, but Im afraid I dont know enough about scripts to even know where to begin


Thanks for the update Carl. Please go through the below blog to get started.


https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-opt...


shloke04
Kilo Patron

HI,



If you have 20 or more than that choices in a select box, based on which you need to show other choices in another variable, I would suggest to follow the below approach:



1) Create a Custom table having two fields(Say Field 1 & Field 2) similar to your Variables.


2) Instead of defining choices in your variable, define the same choices in the two new fields you created in your custom table.


3) Now once the choices are defined, create individual record in your custom table for each of the combination between your choices of field 1 & field 2 which you want to display on your catalog form as shown below:



find_real_file.png


4) Once the above two steps are performed, Navigate back to your catalog Item and create two variables of type "Lookup Select Box" as shown below for reference:



a) For the first Variable, Select the look Up table, Look value field(Field 1 as created in step 1), Lookup Label field(Backend name of Field 1 as defined in step 1)Include None checkbox, Unique values checkbox.



This step would fetch you the choices of your first variable.



find_real_file.png



b) Now, in order to fetch the choices of your second variable, define another variable of Look up select box which will pull out the choices based on your first variable as shown below:



Select the look Up table, Look value field(Field 2 as created in step 1), Lookup Label field(Backend name of Field 2 as defined in step 1)Include None checkbox, Unique values checkbox and a Reference Qualifier as mentioned below:



Reference Qualifier :



javascript: 'u_field_1(backend name of Field 1 created in Custom Table)='+current.variables.Variable 1(name);



In the variable attributes tab mention the following:



ref_qual_elements=First Variable Name



Refer the screenshot below:



find_real_file.png



find_real_file.png



This should work for you, giving you the advantage for better maintenance in future, i.e. instead of writing script every time with add/remove options making it lengthy whenever a new entry comes you just need to update tour custom table.Let me know if you are stuck in achieving the solution.



Hope this helps.Mark the answer as correct/helpful based on impact.




Regards,


Shloke








Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke