Catalog item - how to have concatenation of 2 list collectors in a 3rd one?

vanessaheux
Tera Contributor

Hello

I have 2 list collectors in my catalog item based on same reference table and I would like to fill a third list collector with all values selected from the 2 first list collectors ?

I just need to update the "selected values" of the 2 first List collectors in the 3rd one.

Ex

current.variables.lc1 is the first list collector. User has selected values v1 and v2

current.variables.lc2 is the second one. User has selected values v1 and v3

I would like to dynamically fill the current.variables.lc3 which is the third list collector with all UNIQUE values selected in lc1 and lc2 (so v1, v2 and v3)

 

How to proceed?

Vanessa

1 ACCEPTED SOLUTION

something like this

this client script would be on both the list collectors

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	var val1 = g_form.getValue('lc1').split(',');
	var val2 = g_form.getValue('lc2').split(',');

	// now merge both arrays and remove duplicates and set the value to 3rd one

	var finalArray = arrayUnique(val1.concat(val2));
	g_form.setValue('lc3', finalArray.toString());

}

function arrayUnique(array) {
	var a = array.concat();
	for(var i=0; i<a.length; ++i) {
		for(var j=i+1; j<a.length; ++j) {
			if(a[i] === a[j])
				a.splice(j--, 1);
		}
	}
	return a;
}

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Hi,

script I shared should work fine

Using DOM is not recommended

Regards
Ankur

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

Hello Ankur,

 

My script did not work completely finally (was correct in display but not in script).

So I re-insist on yours and I finally succeed to make it work.

One thing was missing.

The only way to make it work was to modify the list collector and put attribute "glide_list".

 

Now everything is fine. Thanks for your help and insistence and avoid me to use DOM. 🙂