cancel
Showing results for 
Search instead for 
Did you mean: 

get role propertie of a user

sue
Champ in-the-making
Champ in-the-making
Hello

How can I get the role of a user(like Manager) in js file ?
user.propertie ?

thank you
1 REPLY 1

steven_okennedy
Star Contributor
Star Contributor
Hi Sue,

It's easy to get a list of users belonging to a group but not as straightforward to get groups a user belongs to, as I think we have to start with each group we're interested in and check if the user is a memner. Codewise, it can be quite concise though


var user = groups.getUser(person.properties["cm:userName"]);
var grps = groups.getGroups("site_*_Site*", utils.createPaging(-1, 0));

var userRoles = grps.filter(function(grp)
{
   return (grp.getAllUsers().filter(function(usr)
   {
      return usr.userName == user.userName;
   }).length > 0)
})


With this code, the userRoles variable will be an array filled with the ScriptGroup objects representing the Share groups that the currently logged in user is part of, e.g. site_xxxx_SiteManager, site_yyyy_SiteConsumer.  Not terribly efficient but will do the job - we're just finding a list of groups that match the pattern site_XXXX_SiteYYYY and checking if our user is part of each

I'm sure there are probably other ways of doing it as well

Regards

Steven