
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 06:23 AM
var res=[];
var changeArr='';
var changeTask = new GlideRecord('change_task');
changeTask.addQuery('change_request', current.sys_id);
changeTask.query();
while (changeTask.next())
{
changeArr+=','+changeTask.assignment_group.manager;
res.push(current.u_technical_approver_users=changeArr); //
}
here i am getting duplicate values,
one group can have 2 managers with the same name. i want to eliminate the duplicate
can any one suggest?
Harish
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 06:31 AM
I have converted your changeArr from a string to an array for easier processing (and no leading/trailing comma). To make it a comma separated string use arrayName.join(',');
var res=[];
var changeArr=[];
var changeTask = new GlideRecord('change_task');
changeTask.addQuery('change_request', current.sys_id);
changeTask.query();
while (changeTask.next())
{
changeArr.push(changeTask.assignment_group.manager);
res.push(current.u_technical_approver_users=changeArr); //
}
var au = new ArrayUtil();
var newChangeArr = au.unique(changeArr);
var newRes = au.unique(res);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 06:22 AM
Use : var au = new global.ArrayUtil(); // for scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2021 10:56 AM
Can we not use
var au = new ArrayUtil();
in workflow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 06:33 AM
Accenture provided a great hand out in last year's ServiceNow conference that shows one way to use ArrayUtil and I've used this as a reference quite a few times. Hopefully sharing here is okay:
var loggingSource = '\t****FS:CC Lab 1.3 glideRecordLoopRefactored';
// First construct our comparison list
// Remember a one-dimensional array is a comma delimited list of
// values in JavaScript
var incidents = new GlideRecord('incident');
incidents.orderBy('number');
incidents.query();
// push the resultant sys_id recordset to a 1-dimensional array
incidentsList = [];
while (incidents.next()) {
incidentsList.push(incidents.cmdb_ci + '');
}
// remove any duplicates (to minimize our number of loops further)
incidentsList = new ArrayUtil().unique(incidentsList);
// Now do our query with our array using the 'IN' statement
var cmdb_ci = new GlideRecord('cmdb_ci');
cmdb_ci.addQuery('sys_id', 'IN', incidentsList);
cmdb_ci.orderBy('name');
// a bonus! we can now order the list!
cmdb_ci.query();
while (cmdb_ci.next()) {
gs.info('---> {0} {1}',
cmdb_ci.name,
loggingSource);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 06:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 06:30 AM
Hi Chuck,
Can u provide me an example with ArrayUtil to eliminate duplicate?
Harish