- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2022 05:33 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2022 07:03 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 02:28 AM
Hi,
script I shared should work fine
Using DOM is not recommended
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 07:15 AM
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. 🙂