cancel
Showing results for 
Search instead for 
Did you mean: 

Get the user's groups

joshaber
Champ on-the-rise
Champ on-the-rise
How can I, with JavaScript, get the user's groups? We found some reference to a method called getContainerGroups but I have no idea what API that's a part of or how to use it.

Thanks!
2 REPLIES 2

joshaber
Champ on-the-rise
Champ on-the-rise
For anyone who might find this post looking for the answer:


function getUserGroup(person) {
   // person is a Person Node
   var containerGroups = people.getContainerGroups(person);
   var group = containerGroups[0].getQnamePath()
   var p = group.split(":");
   
   return p[p.length-1];
}
That will give you the short name (i.e., "GROUP_Corporate") of the user's first group. Assumes they're part of a group, that you only care about the first group, etc.

louise
Champ in-the-making
Champ in-the-making
A simple question about group name resolution;

How can i get string "GROUP_group1/GROUP_group1.1" from qnamePath style "/sys:system/sys:authorities/usr:GROUP_group1/usr:GROUP_group1.1" result or other method?

Example code below…

Javascript code:

var userName = "admin";
var user = people.getPerson(userName);
var model.groups = people.getContainerGroups(user);

Freemarker code:

   <#list groups as group>
   {
      "id": "${group.name?js_string}",
      "nodeRef": "${group.nodeRef?js_string}",
      "qnamePath": "${group.qnamePath?js_string}",
      "displayPath": "${group.displayPath?js_string}",
      "url": "${group.url?js_string}",
      "parentNodeRef": "${group.parent.nodeRef?js_string}"
   }<#if group_has_next>,</#if>
   </#list>

Output:


   {
      "id": "2c11331f-2897-4fbb-9114-4424dffe5002",
      "nodeRef": "user://alfrescoUserStore/2c11331f-2897-4fbb-9114-4424dffe5002",
      "qnamePath": "/sys:system/sys:authorities/usr:GROUP_group1/usr:GROUP_group1.1",
      "displayPath": "/94cace60-351a-4e14-87a4-73321b9c9c9d/9bdfa029-0973-48e5-88fb-3aa0ab21e94c/5b44c49b-d9ce-4142-97bf-16c2090bcdac",
      "url": "/n/browse/user/alfrescoUserStore/2c11331f-2897-4fbb-9114-4424dffe5002",
      "parentNodeRef": "user://alfrescoUserStore/5b44c49b-d9ce-4142-97bf-16c2090bcdac"
   }