Setting A Default Filter On Variable List Collectors

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!

4 Comments

  1. Hi Hmeid,

    I am trying to pass script include in this filter but it’s not working. Could you please suggest how to achieve this.

    Script Include:
    function u_getGroupUsers(){
    var usrsList = ‘ ‘;
    var varGroup = current.variables.ref_ad_group;
    var usr = new GlideRecord(‘u_user_group_member’);
    usr.addQuery(‘u_group’, varGroup);
    usr.query();
    while(usr.next()) {
    if (usrsList.length > 0) {
    //build a comma separated string of groups if there is more than one
    usrsList += (‘,’ + usr.u_user);
    }
    else {
    usrsList = usr.u_user;
    }
    }
    // return a list of sus_user id’s for the selected company
    return ‘sys_idIN’ + usrsList;
    }

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s