- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 05:23 PM
Hello Everyone,
I have an interesting requirement where end users are not allowed to rename/delete attachment in portal. End user having both scenario which they have snc_internal or no role to user. And for user who don't have any role have solution like !gs.hasRole() == true.
My question is how to we find the user who have exactly snc_internal role?
can some one help me on this. @Ankur Bawiskar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 07:46 PM
HI @SNOW44 ,
I trust you are doing great.
PLease find the below solution for the same.
// Check if the current user has the snc_internal role
function hasSNCInternalRole() {
var hasRole = false;
var user = gs.getUser();
var roles = user.getRoles();
for (var i = 0; i < roles.size(); i++) {
if (roles.get(i) == 'snc_internal' && roles.size() == 1) {
hasRole = true;
break;
}
}
return hasRole;
}
// Example usage
if (hasSNCInternalRole()) {
// User has only the snc_internal role
gs.info("User has exactly the snc_internal role.");
} else {
// User does not have exactly the snc_internal role
gs.info("User does not have exactly the snc_internal role.");
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 05:42 PM
Hi @SNOW44 ,
Query User has a role table in Business Rule and checks user has no role as well as snc_internal by pushing into an array and check the array length and index of snc_internal.
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID());
gr.query();
answer = gr.hasNext()
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 05:45 PM
Thanks Sumanth, will check and comeback!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 07:46 PM
HI @SNOW44 ,
I trust you are doing great.
PLease find the below solution for the same.
// Check if the current user has the snc_internal role
function hasSNCInternalRole() {
var hasRole = false;
var user = gs.getUser();
var roles = user.getRoles();
for (var i = 0; i < roles.size(); i++) {
if (roles.get(i) == 'snc_internal' && roles.size() == 1) {
hasRole = true;
break;
}
}
return hasRole;
}
// Example usage
if (hasSNCInternalRole()) {
// User has only the snc_internal role
gs.info("User has exactly the snc_internal role.");
} else {
// User does not have exactly the snc_internal role
gs.info("User does not have exactly the snc_internal role.");
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 09:06 PM
what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader