Message Boards

Doubts when try yo obtaint the members of a group.

Daniel G, modified 2 Years ago.

Doubts when try yo obtaint the members of a group.

Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts

Hi,

I want to obtain the members of a site, but I am not finding the way to do it. I thinks it has to be an easy thing, but I am not able to do it. Anyone can help me? I would like to get the same users than the ones that are showed in the members tab of control panel

Thanks in advance

Regards

thumbnail
Russell Bohl, modified 2 Years ago.

RE: Doubts when try yo obtaint the members of a group.

Expert Posts: 291 Join Date: 2/13/13 Recent Posts

I'd start with userLocalService.getGroupUsers(long groupId);

 As a proof of concept, run this script from Server Administration > Script and make sure it gives you the count that you see in the Site Members UI (substitue your site's groupId):

// ### Groovy Sample ###

number = com.liferay.portal.kernel.service.UserLocalServiceUtil.getGroupUsersCount(20123);

 

Daniel G, modified 2 Years ago.

RE: RE: Doubts when try yo obtaint the members of a group.

Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts

Hi,

Thanks in advance. That answer is not working because there is users which are in the site because they belong to an user group which is assigned to the site.

This is the solution that is working for me, for anyone who can need it

	public static List<User> getUsersOfSite(long groupId, long companyId){
        LinkedHashMap<String, Object> userParams = new LinkedHashMap();
        userParams.put("inherit", Boolean.TRUE);
        userParams.put("usersGroups", groupId);
        
        long count= UserLocalServiceUtil.searchCount(companyId, null,WorkflowConstants.STATUS_APPROVED,
                userParams);

        List<User> users = UserLocalServiceUtil.search(companyId, null ,WorkflowConstants.STATUS_APPROVED,
                userParams, 0, (int) count, (OrderByComparator) null);
        List<User> returnList = new ArrayList<User>();
        
        
        return returnList;
	}
	

Thanks again for the help

 

Regards,

thumbnail
Russell Bohl, modified 2 Years ago.

RE: RE: Doubts when try yo obtaint the members of a group.

Expert Posts: 291 Join Date: 2/13/13 Recent Posts

Well it doesn't sound like I was much help but I'm glad you got it sorted. What you did looks like what I see in the Site Memebership code, so nice work.