
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2024 02:23 PM
I have this script where I am attempting to take 300+ names in the assigned to field that show as a query result and then making the array have no duplicates. I've tried the ArrayUtil.unique, indexOf, and ! .contains options with no change.
Any help would be appreciated.
var arrUtil = new ArrayUtil();
var groupMembers = [];
var list = new GlideRecord("sn_compliance_policy_acknowledgement_instance"); //Look at the Policy Ack table
list.addEncodedQuery("policy_acknowledgement.active=true^state=1"); //Where the campaign is active, and state is no response
list.orderBy(list.assigned_to); //order by the assigned to.
list.query();
while (list.next()) { //While there is a result
if (!arrUtil.contains(groupMembers, list.assigned_to)) { //see if that person is in the array already.
groupMembers.push(list.assigned_to); //if not, then add them to the array.
}
for (var i = 0; i < groupMembers.length; i++) { //show me the array
gs.info(groupMembers[i]);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2024 01:49 PM
I went another way with it that was much easier and more efficient.
var a = gs.getUserID();
var list = new GlideRecord("sn_compliance_policy_acknowledgement_instance");
list.addEncodedQuery(
"policy_acknowledgement.active=true^state=1^assigned_to="+a
);
list.setLimit(1);
list.query();
if (!list.next()) {
var groupMembership = new GlideRecord("sys_user_grmember");
groupMembership.addEncodedQuery(
"group=d7a8e8174710c610c79c0f68436d4379^user="+a
);
groupMembership.query();
if (groupMembership.next()) {
groupMembership.deleteRecord();
// gs.info("User removed from group");
} else {
// gs.info("use has no acks left, and not in group.");
}
// gs.info(list.getDisplayValue());
} else {
// gs.info("user has acknowledgements left to complete.");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2024 01:49 PM
I went another way with it that was much easier and more efficient.
var a = gs.getUserID();
var list = new GlideRecord("sn_compliance_policy_acknowledgement_instance");
list.addEncodedQuery(
"policy_acknowledgement.active=true^state=1^assigned_to="+a
);
list.setLimit(1);
list.query();
if (!list.next()) {
var groupMembership = new GlideRecord("sys_user_grmember");
groupMembership.addEncodedQuery(
"group=d7a8e8174710c610c79c0f68436d4379^user="+a
);
groupMembership.query();
if (groupMembership.next()) {
groupMembership.deleteRecord();
// gs.info("User removed from group");
} else {
// gs.info("use has no acks left, and not in group.");
}
// gs.info(list.getDisplayValue());
} else {
// gs.info("user has acknowledgements left to complete.");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2024 02:30 PM
good to know ... finally you got the result.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution