- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 11:05 AM
I'm relatively new at SN, and working on User Criteria for Knowledge. The requirement is for users with a specified company that have no roles (explicit or inherited). The company I can pick using the selector, but the absence of roles looks like it would require a bit of a script. This seems like it should work:
answer = !(gs.getUser().getRoles().toString().length); // return true if no roles are present
but if anyone has a better idea (ideally without a script at all) I'd love to hear it.
I'm skeptical about using .length without explicitly converting to String first (I've been burned by such before) but the User Roles type is described as "extends String", so it's neither a string nor an array. Since I only care that there's either something or nothing in the list, I don't need it to be an array, but I do need to be able to rely on the .length property working correctly.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 01:19 PM
Pretty sure that would work, but after working around Glide for a few months now, I think what might be cleaner is something like:
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID());
gr.query();
answer = gr.hasNext()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 11:15 AM
this does the work:
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', 'bfb9aa5bdbf323003660a0f2ca961966');
gr.query();
if (!gr.next()){
gs.log('user has no roles');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 01:19 PM
Pretty sure that would work, but after working around Glide for a few months now, I think what might be cleaner is something like:
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID());
gr.query();
answer = gr.hasNext()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2019 02:57 AM
your script is better and correct. thanks!