What is the best way to compare and find common elements between two "Lists" field types referencing the same table?

bcronrath
Kilo Guru

Right now what I am doing is returning the lists from each different object as a string, parsing them out to two arrays based on the delimiter, then iterating through each array to output the common elements.

I'm just wondering if servicenow has a more straightforward way to do this, that might not have to involve me looping through in this fashion each time I want to find common referenced items between two lists referencing the same table.

2 REPLIES 2

bernyalvarado
Mega Sage

Hi Brian,



The following solution proposed by ctomasi should be of help.



Glide List Differ



Also... please note the comment on that post which suggests to use diff, intersect, and union when using the ArrayUtil.



Thanks,


Berny


guhann
Mega Guru

Hi Brian,



You can use the intersect method of ArrayUtil