How to automatically run filter on list collector

dennisjames
Tera Contributor

Hey Guys,

I have a catalog item that I am working on, and want to filter my list collector based on an option that is chosen. I have a client script that will apply the filter and have it show up on the page, but it still requires the user to hit "Run Filter". I've seen this scenario mentioned on this thread - Catalog List Collector variable: Set filter? and it seems they solved it, but didn't see anything definitive on how it was done.

Here is a basic one that I was testing with in my DEV instance as a start off. How would I get it to set the filter up and have the filter run on the list collector without manually hitting the button?:

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

          return;

    }

     

      machineg_filter.reset();

      machineg_filter.setQuery("sys_id=3a63d606c611222500487ae00a5bf3b8");

      machineg_filteracRequest(null);

   

}

1 ACCEPTED SOLUTION

Rajesh M1
Giga Guru

use below code in onchange script to run the filter dynamically. Use Timeout function to set some delay


function onChange()


{
var collectorName = 'Responsibilities';
      var filterString = 'u_user='+g_form.getValue('Requestor')+'^u_tme_active=true^u_tme_role_assigned=true';
     
      //Find the filter elements
      var fil = gel('ep');
      //Hide the filter elements by un-commenting the following lines
      /*fil.rows[0].style.display = 'none';
      fil.rows[1].style.display = 'none';
      fil.nextSibling.rows[0].style.display = 'none'; //Filter description text*/


      //Reset the filter query
      eval(collectorName + 'g_filter.reset()');
      eval(collectorName + 'g_filter.setQuery("' + filterString + '")');
window.setTimeout(fun21,4000,answer);


}



function fun21()


{


var collectorName1 = 'Responsibilities';


eval(collectorName1 + 'acRequest(null)');


}


View solution in original post

5 REPLIES 5

marcguy
ServiceNow Employee

This article should give you everything you need to know:



Changing the Filter of a List Collector Variable via Client Script - ServiceNow Guru


Rajesh M1
Giga Guru

use below code in onchange script to run the filter dynamically. Use Timeout function to set some delay


function onChange()


{
var collectorName = 'Responsibilities';
      var filterString = 'u_user='+g_form.getValue('Requestor')+'^u_tme_active=true^u_tme_role_assigned=true';
     
      //Find the filter elements
      var fil = gel('ep');
      //Hide the filter elements by un-commenting the following lines
      /*fil.rows[0].style.display = 'none';
      fil.rows[1].style.display = 'none';
      fil.nextSibling.rows[0].style.display = 'none'; //Filter description text*/


      //Reset the filter query
      eval(collectorName + 'g_filter.reset()');
      eval(collectorName + 'g_filter.setQuery("' + filterString + '")');
window.setTimeout(fun21,4000,answer);


}



function fun21()


{


var collectorName1 = 'Responsibilities';


eval(collectorName1 + 'acRequest(null)');


}


Raj,



What does the 'ep' signify in gel('ep')?



Thanks,



Laurie


dennisjames
Tera Contributor

Thanks to both for the replies. Did what I needed