How to script if user is a member of a group?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 09:34 AM
The overall task is to give access to a field if the person viewing the record is the creator or a member of the assigned group.
I've commented out line by line to see if I can get anything to work. Right now, this is saying if the current user is a member of the current Assigned group then the condition is true, if I'm correct.
/*if(current.sys_created_by.equals(gs.getUserName())) {
answer = true;
}else*/ if(gs.getUser().isMemberOf(current.assignment_group)){
answer = true;
}/*else if(current.assigned_to.equals(gs.getUserName())){
answer = true;
}*/else{
answer = false;
}
As you can see from the Security Debugging, this is false. So maybe it's coded wrong. The Requires role has the role that the user I'm testing with belongs to.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 09:44 AM
Hello,
Can you please trey below code?
var userObj = gs.getUser();
if (userObj.isMemberOf(current.assignment_group.sys_id) || current.opened_by == gs.getUserID())
{
answer = true;
}
else
{
answer = false;
}
Best regards,
Boyan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 10:23 AM
var userObj = gs.getUser();
if (userObj.isMemberOf(current.assignment_group.sys_id) || current.opened_by == gs.getUserID()){
answer = true;
}else{
answer = false;
}
Didn't work.
var userObj = gs.getUser();
if (userObj.isMemberOf(current.assignment_group.sys_id)){
answer = true;
}else if(current.opened_by == gs.getUserID()){
answer = true;
}else{
answer = false;
}
Did not work either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 09:44 AM
//untested code. try the following block
if(current.sys_created_by == gs.getUserID())
{
answer = true;
}
else if(gs.getUser().isMemberOf(current.assignment_group.name))
{
answer = true;
}
else
{
answer = false;
}
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 09:44 AM
Check out this: With ACL you can achieve this
1. Here sys_created_by is string field which stores user id who created a record. SO you need to use gs.getUserName().
2. Here assigned_to is reference field, so you need to compare with sys_id and we can get it from gs.getUserID()
if(current.sys_created_by== gs.getUserName()) {
answer = true;
}else if(gs.getUser().isMemberOf(current.assignment_group)){
answer = true;
} else if(current.assigned_to == gs.getUserID()){
answer = true;
}else{
answer = false;
}
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade