Update: In Helsinki this can be achieved out of the box, so make sure if this is implemented to remove it on an upgrade. Not sure it’ll play nicely with the OOB method. Thanks Goran for letting me know!
I was creating a service request today and for the first time in a long time I used the List Collector variable. As soon as I started using it I remembered why I didn’t like it. There just aren’t enough options on there (reference qualifiers, default filter etc). But today I had no alternative so wanted to figure out how to set a default filter. The only way I could find was the solution provided by ServiceNow Guru. Works a treat but thought I’d share a different approach just for some information.
Well it turns out there’s a jelly variable that can be used to set a default filter called jvar_initial_filter which accepts an encoded query. Of course as the variable XML is on the server, you’re unable to edit it to allow it to be a parameter. So instead, all I did was create a UI macro with one line in it
<j:set var="jvar_initial_filter" value="your_encoded_query_here"/>
Then I just created a Macro type variable just before the list collector and pointed it to my newly created macro. The List Collector then uses this jelly variable. The reason for this is that jelly variables are not scoped to a particular script. They are inherited throughout the page and so can be written and rewritten by any Jelly script on the page. Which is another important takeaway if you have multiple ui macros in a page, be careful about variables clashing. You can get some very strange behaviour!