- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 11:40 AM
Hello,
How can I remove 2 items from a list collector? Every record will have multiple items in the list collector.
This is what I have and it is not working:
var gr = new GlideRecord("incident");
gr.addEncodedQuery("u_userLIKEd5f94d1487b9b0d0d2c7c9d6cebb355a^ORu_userLIKE3c23dcaa871a34d4d2c7c9d6cebb353d");
gr.setLimit(1);
gr.query();
while (gr.next()) {
var users = gr.u_user.toString();
var usersArr = users.split(",");
gs.print("List End: " + usersArr);
if (usersArr.includes("d5f94d1487b9b0d0d2c7c9d6cebb355a")) {
usersArr.splice("d5f94d1487b9b0d0d2c7c9d6cebb355a");
}
if (usersArr.includes("3c23dcaa871a34d4d2c7c9d6cebb353d")) {
usersArr.splice("3c23dcaa871a34d4d2c7c9d6cebb353d");
}
gs.print("List End: " + usersArr);
}
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 12:11 PM
Hi,
Can you give more information as to how it is not working?
Are you seeing errors?
With that said, you can try using:
var gr = new GlideRecord("incident");
gr.addEncodedQuery("u_userLIKEd5f94d1487b9b0d0d2c7c9d6cebb355a^ORu_userLIKE3c23dcaa871a34d4d2c7c9d6cebb353d");
gr.setLimit(1); //if you're limiting it to one, why use while loop? unless you're just testing with one...
gr.query();
while (gr.next()) {
var users = gr.getValue('u_user');
var usersArr = users.split(",");
gs.print("List End: " + usersArr);
var index1 = usersArr.indexOf("d5f94d1487b9b0d0d2c7c9d6cebb355a");
var index2 = usersArr.indexOf("3c23dcaa871a34d4d2c7c9d6cebb353d");
if (index1 > -1) {
usersArr.splice(index1, 1);
}
if (index2 > -1) {
usersArr.splice(index2, 1);
}
gs.print("List End: " + usersArr);
}
There's a few ways to do this, but the above would be one.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 02:36 PM
Ahhhhh okay I see. I was adding the additional logic because I was missing some stuff. It works now! Thanks again for all your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 03:05 PM
Awesome, haha. Glad you got it!
If any other reply was Helpful, please mark it as Helpful.
Take care! 🙂
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!