How to set/clear a list collector in the catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 01:45 PM
So I see this question come up a lot: "How do I change the filter on a list collector in the catalog?"
Well, Mark Stanger had a great right-up over on his sncguru site on how to do this pre-service portal. The old way of doing things just won't work for the service-portal, as it uses a new API for the list collector type variables in the catalog.
This means that if you have users visiting the catalog item from both the platform and the service-portal, then you'll have to create two scripts, marking one to run on desktop only, and the other to run as mobile only (as the service-portal counts as a mobile platform, even on your computer).
For the service-portal (mobile) script, it's pretty simple. I like the new API, it's clean, and it allows you to easily clear the values without the DOM manipulation:
g_form.setValue('list_collector_name', ''); //this will clear out the list collector
var myListCollector = g_list.get("list_collector_name");
myListCollector.reset();
myListCollector.setQuery("encoded query goes here");
Now, if your users will visit in the old CMS portals or in the platform, you'll still have to (at least as of early Helsinki) use the old API, which is what Mark Stanger wrote about here:
Changing the Filter of a List Collector Variable via Client Script - ServiceNow Guru
Yes, that uses DOM, if you can do it better without DOM, then feel free to. However, you will definitely want to come up with a solution if you are going to the angular service-portal, as these scripts will not work on the service portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 07:01 AM
Thank you Gary that was really helpful.
We had the same issue today.
Small addition to your post:
You don't need to create two seperate scripts. Just make on and set it to "both".
In the script you can make a simple "if" to decide when to run which code.
if (window === null)
// Write your mobile compatible code here
else
// Write your desktop compatible code here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 09:07 AM
You could also use a try/catch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2018 05:13 PM
Hi Ben,
I am trying to copy RITM and have few list collector variables.Values are being copied but getting error" Unhandled exception in GlideAjax".
Have tried steps mentioned in KB article ServiceNow KB: Unable to set the value of a list collector using setValue() (KB0622779)
but still no luck.Also used try & catch method.
Any suggesstion?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 01:20 PM
+1
Knowledge article claims issue is fixed in Jakarta, but i still have no luck.