- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:19 AM
Hi guys,
I need to check if the roles from a gliderecord output are inside my array.
Example:
var gr = new GlideRecord("sys_group_has_role");
gr.addQuery("group", current.sys_id);
gr.query();
while (gr.next()) {
!!!CHECK if gr.role is inside my arr!!!
}
I have tried to add the array directly to the query but it is useless because it checks if there are ocurrences but I will not know which one matches and which one doesn't
I have tried indexOf but it is not working for me:
Solved! Go to Solution.
- Labels:
-
Service Level Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:26 AM
} // if your array has name of roles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:26 AM
} // if your array has name of roles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:39 AM - edited 10-31-2022 10:39 AM
Hi @JoaoV,
Try this updated scritps -
var arr = ["admin", "test", "impersonator"];
for (var i = 0; i < arr.length; i++) {
var gr = new GlideRecord("sys_group_has_role");
gr.addQuery("group", current.getUniqueValue());
gr.addQuery("role.name", arr[i]);
gr.query();
gs.info(gr.getRowCount());
while (gr.next()) {
// !!!CHECK if gr.role is inside my arr!!!
gs.info(arr[i]);
}
}
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 10:46 AM
Hi @Sagar Pagar , Thanks for that but as I said in my post I cannot pass the entire array in the query because I will not now which is duplicate and which not.