Glide List Differ
Last week I needed a way to take two lists of comma separated values and determine what the differences were. A customer was looking for a way to do approvals based on values added or removed from a proposed change to a glide_list on a CI. For example, if SOX was added to the glide_list field, they wanted a group approval based on SOX. If PCI was removed, then a different group was required to approve. With a little XML parsing, I was able to get the old and new list values. My script is written to work equally well on any list of comma separated values. I offer to you, free of charge, as-is my GlideListDiffer script include for your use.GlideListDiffer takes two lists of comma separated values and returns an array of objects indicating which have been added (not found in the first list) and which have been removed (not found in the second list.) Here's an example use case:
var list1 = "1,2,3,4,5";var list2 = "2,4,6,8,10";var ld = new GlideListDiffer();var o = ld.listChanges(list1, list2);gs.print(o.length + ' changes found');for (var i = 0; i < o.length; i++) gs.print('action=' + o.action + ' value=' + o.value);
The above example wil produce the following output.
*** Script: 6 changes found*** Script: action=delete value=1*** Script: action=delete value=3*** Script: action=delete value=5*** Script: action=add value=6*** Script: action=add value=8*** Script: action=add value=10
Do yourself a favor and don't call your lists "old" and "new"! "new" is a reserved word in JavaScript and it cost me about 30 minutes. ![]()
https://www.servicenow.com/community/in-other-news/glide-list-differ/ba-p/2280062