How to hide a button based on current user's group membership?

boston019
Mega Expert

Hi,

I have a button I need to hide if the current user is not in a given group.

 

Would that be too much to put into the Condition field?

If so, I found this link which looks helpful but I'm not sure what to put in to actually hide the button (in that link they're hiding State options). Would I just nest the button code in there and add a Return statement? For example:

 

 

 

 

function onLoad() {
  var usr = g_user.getUserID();
  if (!g_scratchpad.grp){
      return; //end function before button displays
    }
  //button code
}

 

 

 

EDIT: Nope, didn't work.

 

1 ACCEPTED SOLUTION

boston019
Mega Expert

I figured it out. In the Condition:

gs.getUser().isMemberOf('group name here') == true

Thanks 🙂

View solution in original post

3 REPLIES 3

Derek Behunin
Tera Guru

Best practice would likely be to call a script include in the UI actions condition field.

In your script include query the grmember table for the currently logged in user, then compare the returned records group fields against the group you're checking if the user is not in.

If you find a match, return false (hide the button)
else return true (show the button)

Let me know if this helps

Hi,

Thanks for your reply.

That produces the following error: "The object "gs" should not be used in client scripts."

boston019
Mega Expert

I figured it out. In the Condition:

gs.getUser().isMemberOf('group name here') == true

Thanks 🙂