Reference qualifier for list collector

SNow35
Giga Guru

Hi All,

I have two variables in my record producer:

1. Customer(this is a reference field)

2.SOF(this is list collector)

I need to create a filter on the "SOF " field on the record producer form so that it only shows SOF records that are associated with the same Company that the record is for. So if the "Customer" field on the record producer   form is set to "XYZ", then only SOF records where the "Company" field on the SOF record EQUALS "XYZ" should be displayed for the user to choose from.

Please let me know how I can achieve this.

Regards,

Shugufta.

1 ACCEPTED SOLUTION

Hi Shagufta,



Please use the updated code :



""


I advice to use an onChange client script which would set the filters to you. The list collector has to refer the right table for records. I had a catalog item where i have used this code,



I would request you to implement something similar(this is a catalog client script):



   


    var collectorName = 'list_collector_field_name'; // the list collector field on the record producer


    var filterString = 'group='+g_form.getValue(' field_name '); // from where the filter is dependent on the record producer



  //Hide the list collector until we've set the filter


    if(typeof(window[collectorName + 'g_filter']) == 'undefined'){


  setTimeout(setCollectorFilter, 100);     //Test if the g_filter property is defined on our list collector.


                                                                                                          //If it hasn't rendered yet, wait 100ms and try again.


  return;


  }


    window[collectorName + 'g_filter'].reset();   // this resets


    window[collectorName + 'g_filter'].setQuery(filterString); //sets the filter


    window[collectorName + 'acRequest'](null); //runs the filter automatically



once its populated it can fetched later in RITM and TASKs.


""



The default values of the list collector should not have no_filter , and as the client script does the task script include and calling script include can be excluded too.



Do reach back if you get struck.



Regards,


Shariq


View solution in original post

35 REPLIES 35

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shaik,



Have an onChange script on customer variable and set the filter of the list collector using below links:


https://www.servicenowguru.com/scripting/client-scripts-scripting/changing-filter-list-collector-var...


Filtering on the List Collector or SlushBucket variable in Helsinki


Reference qualifiers in Service Catalog



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

BALAJI40
Mega Sage

See there was problem with creating reference of list collector based on another variable.


Check this link, Reference Qualifier Issue in List Collector Type Variable



IF both are reference, it should work properly.


I got the script, but not sure about the modifications I need to make:



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


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


          return;


    }


var grp = g_form.getValue('name_grp');


  if(newValue=='') {


  g_form.clearValue('group_mem');


  }


  var group = new GlideRecord('sys_user_grmember');


  group.addQuery('group', grp);


  group.query();


  while(group.next()) {


  var list = group.user;


  var array = list.split(',');


  for(var i=0; i<array.length;i++) {


  var p = new GlideRecord('sys_user');


  p.addQuery('sys_id', array[i]);


  p.query();


  p.query(getMeTheNames);


  }


  }


}



function getMeTheNames(p) {


  var list = new Array();


  while (p.next()) {


  list.push(p.sys_id);


  }


  g_form.setValue('group_mem', list);


}