- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 02:44 AM
Hello,
I have an order guide setup for new hires. Within this guide, the manager must first select the brand the new hire will work for from a reference variable to the company table. I then have a list collector variable with a question_choice reference for hardware the new hires can order (originally variable was a multiple choice that has been turned into a list collector).
I want to hide certain choices depending on the brand they select. For example CompanyA should be able to see everything on the list but CompanyB shouldn't be able to see Macbook and CompanyC shouldn't be able to see Macbook or iPhone.
I have read previous articles of adding it to the reference qualifier but 1) I'm not very good with scripting and 2) I don't know how to add anything in there whilst also incorporating the question=sysID which is already in there.
Please help.
Thanks
Abbie
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:25 AM
Yeah, sure, sorry I misunderstood. In this format you'll want to keep the logic as simple as possible, so to only show 'password' when 'Acer' is selected would look more like this:
var ret = 'question=8aeaab25c0a8001500044f3982c9ecb5'; if(current.variables.v_company.name!="Acer"){ret = ret + '^value!=password';}ret
then you would have to add an if block for every criteria. If it gets too complicated we should try the Script Include approach where you can lay out all of the logic and have it return only the correct values within a full script instead of trying to string it all together like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 11:54 AM
Hi Abbie!
I would be happy to help you with this. Like most things in ServiceNow, there's more than one way to do this. Here's potentially the easiest way, but if it gets too complicated we can put this in a Script Include that's called by the reference qualifier, or use an onChange Catalog Client Script to alter the filter on the List Collector. All you need to do is make your Reference qualifier and Variable attributes on the List Collector variable look more like this:
where v_company is the name of the Brand reference variable, and the rest you replace with your values. Here's the text of the qualifier following javascript :
var ret = 'question=8aeaab25c0a8001500044f3982c9ecb5'; if(current.variables.v_company.name=="Acer"){ret = ret + '^value!=password';}if(current.variables.v_company.name=="3Com"){ret = ret + '^value!=email^value!=desktop_app';}ret
and the Variable attributes, which ensures the List Collector variable will be updated when the value of the Brand variable changes:
no_filter=true, ref_qual_elements=v_company
Have fun!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 05:50 AM
Hello! Apologies it has taken so long to reply!
I can get the javascript to work, but it is doing the opposite of what I want. Using the example above, it is removing 'Password' from the list when 'Acer' is selected. I want it to only show 'password' when 'Acer' is selected, and remove it when any other company apart from 'Acer' is selected.
Is this possible?
Thanks
Abbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:25 AM
Yeah, sure, sorry I misunderstood. In this format you'll want to keep the logic as simple as possible, so to only show 'password' when 'Acer' is selected would look more like this:
var ret = 'question=8aeaab25c0a8001500044f3982c9ecb5'; if(current.variables.v_company.name!="Acer"){ret = ret + '^value!=password';}ret
then you would have to add an if block for every criteria. If it gets too complicated we should try the Script Include approach where you can lay out all of the logic and have it return only the correct values within a full script instead of trying to string it all together like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:35 AM
Thank you, worked perfectly!