How to script if user is a member of a group?

Robert Campbell
Tera Guru

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.

6 REPLIES 6

Boyan1
Kilo Sage

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

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.

vkachineni
Kilo Sage
Kilo Sage

//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;
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

AbhishekGardade
Giga Sage

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

Thank you,
Abhishek Gardade