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

Pratiksha Kalam
Kilo Sage

Hi

Create a display Business rule with script as. Place the below script between function templates in script body.

 

g_scratchpad.grp = gs.getUser().isMemberOf('PASS GROUP NAME HERE');  

 

Now update the client script as

 

function onLoad() {

 

  var usr = g_user.getUserID();

 

  var gate = g_form.getValue('u_field');

 

  if (gate == 'true' && !g_scratchpad.grp){

 

      g_form.removeOption('state', '3'); //closed complete

 

      g_form.removeOption('state', '4'); //closed incomplete

 

      g_form.removeOption('state', '7'); //closed skipped

 

    }

 

}

If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful and Accepted Solution buttons.

regards,

pratiksha

Robert Campbell
Tera Guru

I haven't tried all suggestions yet but it seems that some are posting the same thing I'm already doing.  This is my updated script:

if(current.sys_created_by == gs.getUserID()){
	answer = true;
}else if(current.sys_create_by == gs.getUserName()){
	answer = true;
}else if(gs.getUser().isMemberOf(current.assignment_group)){
	answer = true;
}else if(gs.getUser().isMemberOf(current.assignment_group.name)){
	answer = true;
}else{
	answer = false;
}

 

The task I am viewing is created by the user I'm using AND is assigned to the team that the user is a member of.  The field is still read-only.  If I remove the script, bc the user has the role, they are able to edit the field but they need to have the role AND match the conditions laid out by the script.

I will try other suggestions now.