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

Hi,



Alright, the reason being , you maybe sending a list of comma separated values from the other list collector ( even though a list length of 1 element is send)



But, this works provided that the role field supports the logic role is one of list of values.



Now remember list collector being a form of advanced reference qualifier,only sys id of the records are captured.


Take the advantage of glideAjax API.


Syntax could be.



var val= g_form.getValue(field);


var str1='';


var ga = new GlideAjax;


..(script name);


..(function name):


...


...



var filterString = 'u_roleIN'+str1



function ()


{


str1= answer:


return str1;


}




In the script include:



Make it client callable,


function name(val){


var arr=[];


var gr = new GlideRecord('table where the record is stored/fethched');


gr.addQuery('sys_id','IN', val);


gr.query();


while(gr.next()){


arr.push( gr.getValue('name') ); send sys id if you want to set filter with sys id.


}


return arr.join(',');


}



I hope you are getting the logic.


HI SHARIQUE,


please help me how to encode the setQuery,


i want to add one more condition to the above list collector filter.



please help me


Hi Deepu,



Please provide your piece of codes and the exact requirements.


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


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


          return;


    }


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


var filterString = 'location='+g_form.getValue('cnb_pick_up_location');//location is feild on ci table and cnb_pick_up_location is variable of listcollector


    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);


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


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


    }



now i want to add the condition:(install_status==instock) to above filterstring,


install_status is feild name on ci table


simply said filterout the records based on location == variable.location AND install_status ==instock


Hi Deepu,



This is not the correct way to do it.


Try doing it by



var filterString = 'location='+g_form.getValue('cnb_pick_up_location')+'install_status=104';   //or install_status=instock.