To clear List Collector values on change of a variable in SR.

zabeeulla2
Kilo Expert

Hi All

                  I have a requirement to clear all the options selected in the right slush busket from a list collector when a variable   say ' Customer' is changed instead of moving them to the left side because there is already an onchange script for the filter for every change of customer a set of new values get populated in the list collector. So when I change the customer the selected values in the list collector should disappear and show none .

                                                Immediate help is appreciated.

find_real_file.png

this is for one customer when I change the customer it should be as shown below

find_real_file.png

Thanks

Zabee.

1 ACCEPTED SOLUTION

Try this:


OnChange of customer:



var varName = 'Name of your list collector';


var rightBucket = gel(varName + '_select_1');


var selectedOptions = rightBucket.options;



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


             


    //Check for the item to add here based on sys_id


    var value = selectedOptions[i].value;


        rightBucket.remove(value);



    }


View solution in original post

24 REPLIES 24

Hi mujtaba,


                                      The script says that it cannot recognize 'options' in   var selectedOptions = rightBucket.options;


can you please help me regarding this.




Thanks ,


Zabee.


https://demo003.service-now.com/navpage.do



I have created a maintain item "Test List Collector" on demo instance. The code is working. Please check and modify the script as per your requirement. Mark this answer as correct or helpful if this helps you.


Hi Mujtaba,


                                      Thanks a lot for your help this code actually worked.



var varName = 'Devicename';


var rightBucket = gel(varName + '_select_1');


var selectedOptions = [rightBucket];


//alert('afteroptions');


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


    //Check for the item to add here based on sys_id


    var value = selectedOptions[i].value;


//alert('inside');


        rightBucket.remove(value);


//alert('hi');


    }



Thanks,


Zabee.


Hi Mujtaba,


                                      I have an issue that only half of them among the options selected are removed like if I select 2 options and change the customer then there will be one item remaining in the right bucket instead of disappearing. I checked with the item in demo instance created by you and it has the same issue too.


                  Immediate help is appreciated.



Thanks,


Zabee.


try this loop:



var selectedOptions = rightBucket.options;


for (var i = selectedOptions.length - 1; i > -1; i--)


{


                                      rightBucket.remove(selectedOptions[i]);    


                      }