- 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 07:30 PM - edited 10-31-2022 07:35 PM
Hi @JoaoV,
I would suggest to get unique elements before passing it to query.
var arr = ["admin", "test", "impersonator", "admin", "itil"];
var uniqueArray = [];
var arrUtil = new global.ArrayUtil();
uniqueArray = arrUtil.unique(arr); // get Unique elements
for(var i = 0; i < uniqueArray.length; i++){
var gr = new GlideRecord("sys_group_has_role");
gr.addQuery("group", "725eb7f4db9532000454f1351d96198c");
gr.addQuery("role.name", uniqueArray[i]);
gr.query();
gs.info(gr.getRowCount());
while (gr.next()) {
// !!!CHECK if gr.role is inside my arr!!!
gs.info(uniqueArray[i]);
}
}
Thanks,
Sagar Pagar