- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 02:44 AM - edited 10-31-2022 02:48 AM
Hello Experts,
I have a list collector field on the Change Request form which references to sys_user_group table
For example, the current field holds three groups called "A, B, and C" now I have added "D, E" groups manually
Previous list collector fields array values = [A, B, C]
Current list collector fields array values = [A, B, C, D, E]
The requirement is to fetch newly added groups and post them in the change request audit history, so in the current scenario D, E should be set to "work_notes" field
Scenario: I want to compare the current list array values with the previous list array and need to fetch unmatched array values
I have used the below logic but not working as expected
var currentAuthorizationApproval = current.u_authorization_approval_groups.toString().split(",");
var previousAuthorizationApproval = previous.u_authorization_approval_groups.toString().split(",");
var final1 = getMatch(currentAuthorizationApproval, previousAuthorizationApproval);
gs.addInfoMessage(" final=>" + final1);
function getMatch(a, b) {
var matches = [];
for (var i = 0; i < a.length; i++) {
for (var e = 0; e < b.length; e++) {
if (a[i] != b[e]){
matches.push(a[i]);
gs.addInfoMessage("a[i]=>" +a[i]);
}
}
}
return matches;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 03:15 AM - edited 10-31-2022 03:21 AM
Hi @Shantharao ,
Below code should work:
var currentAuthorizationApproval = current.getValue("u_authorization_approval_groups").split(",");
var previousAuthorizationApproval = previous.getValue("u_authorization_approval_groups").split(",");
var arrayUtil = new ArrayUtil();
var final1 = arrayUtil.diff(currentAuthorizationApproval , previousAuthorizationApproval )
gs.addInfoMessage(" final=>" + final1);
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 03:00 AM - edited 10-31-2022 03:01 AM
Hi Shantharao,
Try the below code in function -
function getMatch(a, b) {
var matches = [];
for (var i = 0; i < a.length; i++) {
for (var e = 0; e < b.length; e++) {
if (a[i] != b[e]){
matches.push(a[i].toString());
gs.addInfoMessage("a[i]=>" +a[i]);
}
}
}
return matches;
}
Please mark this answer as Helpful if this works.
Thanks,
Chinmay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 03:20 AM
Hi Chinmay,
I have tried pushing as a string but no luck, is there any other way to fix this issue
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 03:02 AM
Try using Array Utils from servicenow
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 03:15 AM - edited 10-31-2022 03:21 AM
Hi @Shantharao ,
Below code should work:
var currentAuthorizationApproval = current.getValue("u_authorization_approval_groups").split(",");
var previousAuthorizationApproval = previous.getValue("u_authorization_approval_groups").split(",");
var arrayUtil = new ArrayUtil();
var final1 = arrayUtil.diff(currentAuthorizationApproval , previousAuthorizationApproval )
gs.addInfoMessage(" final=>" + final1);
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh