Client Script to get users of a group

jewellauber
Tera Expert

I have a request to conditionally grant read/write access to users if they are apart of a specific group.  Right now I'm trying to figure out how to retrieve this information through client script.  I've been going through lots of articles to learn how to write this client script.  I have the addInfoMessage to attempt to see what is being retrieved and how it looks.

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   
  var ga = new GlideAjax('global.getUserGroups');
    ga.addParam('sysparm_name', 'getUserGroupListRQ');
    ga.addParam('sysparm_grp_arr', g_form.getValue("group"));
    ga.getXML(function(response) {
        var result = response.responseXML.documentElement.getAttribute('answer');
        g_form.addInfoMessage(result);
       
    });  


}
5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

What you want to do is create a write ACL on the table as a whole, or the fields in question.  To allow access if the current user is a member of a certain group, in the script you can use something like:

if (gs.getUser().isMemberOf("Enterprise Architect Group")) {
    answer = true;
} else {
    answer = false;}

 

Hi Brad thanks for your response.  I have to only allow these users access to a few fields I would need to create an acl for each field right?  I was assuming with the client script I can tackle all fields in a single script.

You can, but securing fields on the client is not the best as there is a brief delay while the form is loading when the field could still be updated, and edits could still be made via list view and potentially other methods.

 

If you go the client script route, you'll want to pass in the current user as another parameter on the GlideAjax using 

g_user.userID

You don't need to pass in the value of a group field unless you're trying to determine if the current user is a member of that group - like  a user can update incident fields if they are a member of the assignment_group.

 

How far did you get in your Client callable getUserGroups Script Include?

Yes that's exactly what I am trying to do, checking if the member is in one of 3 groups.  The script include was already created by another developer.  So I am using that to check the user membership, global.getUserGroups.