- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2020 08:54 PM
Hi Guys,
Need some assistance here.....
I have a catalog request form that populates a list collector based on some fields selection. I need to hide this list collector if the listed values are exactly the same as the other list collector on the form.
How can I compare 2 list collectors?
Thank you in advance.
Regards,
Jocelyn
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2020 10:28 PM
Hi,
You should not get that error.
For sample purpose : run this code in scripts background and check if this works
var arrayUtil = new ArrayUtil();
var a1 = new Array("a", "b", "c");
var a2 = new Array("c", "d", "e");
gs.print(arrayUtil.diff(a1, a2));
If this works , then put your sample code also in scripts background and check .
It shoudl work most likely. I would suggest putting some print statement for print list array1 and array2 in your code , it will help you to identify rootcause.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2020 09:34 PM
Hi,
You need to take the list collector values in array
var arrayListCollector1 = [];
var arrayListCollector2 = [];
var arrayListCollector1 = current.variables.your_list_collector_variable1.toString().split(',');
var arrayListCollector2 = current.variables.your_list_collector_variable2.toString().split(',');
After that apply for loop.
for (var i = 0; i < arrayListCollector1.length; i++) {
if (arrayListCollector1[key] == (arrayListCollector2[key] )) {
// write logic here
}
else{
// write logic here
}
Hope this will help you.
Regards,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2020 10:08 PM
Hi Sagar,
Thanks for your email.
I am doing this using catalog client script and "current" is not valid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2020 09:47 PM
Hi JLeong,
Convert the list collector to an array like below
var listcollector1 = your_field_name_here.toString();
var array1 = listcollector1.split(',');
var listcollector2 = your_field_name_here.toString();
var array2 = listcollector2.split(',');
And then compare both
var arryUtil = new ArrayUtil();
arryUtil.diff(array1,array2);
gs.info(arryUtil);
This will
Return an array of items from array1 that were not found in either array 2. Duplicates are removed from the result.
Mark my ANSWER as CORRECT and HELPFUL if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2020 10:06 PM
Hi,
Thanks for helping!!! I get an error: ArrayUtil is not defined