Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
Reply
New Contributor
mkoman
Posts: 5
Registered: ‎06-21-2011
My Carrier: developer
Accepted Solution

How can I get user ids of a group?

Hello,

 

I'm newbie in BES development but I hope, You can help me.

 

 

I have group with 3 users and a I want to get the list of user ids.

 

1. I found a group:

for (Group itr:result.getGroups()) {
            String resultGroupName = itr.getLocaleNameAndDescription().get(0).getName();
            if(resultGroupName.equals(groupName)) {

                     //now I'm trying to get users of group, i will describe it in the next paragraph

            }

}

 

2. I'm trying to get users of group:

 

GroupUsers groupUsers = itr.getGroupUsers();

 

but I obtain NullpointerException.

 

Please, can you help me, where i made a mistake?

 

3. I also tried to use getgetGroupMember() but I got empty list:

List<GroupMember> groupMembers = itr.getGroupMember();

 

What's the difference between objects GroupMember and GroupUser?

Please use plain text.
Developer
Developer
KPK
Posts: 18
Registered: ‎06-01-2011
My Carrier: Rogers

Re: How can I get user ids of a group?

Hi.

This works for me but I am using C# and BES API 5.0.2

 

//you will need to supply the group ID

int mygroupID = 7;

getGroup GroupRequest = new getGroup();

GroupRequest.groupId = mygroupID;

GroupRequest.locale = "en_US";

GroupRequest.loadGroupChildGroups = false;

GroupRequest.loadGroupDirectAssignments = false;

GroupRequest.loadGroupDirectUsers = true;

GroupRequest.loadGroupParentGroups = false;

getGroupResponse GroupResponse = coreWebService.getGroup(GroupRequest);

GetGroupResult GroupResult = GroupResponse.returnValue;

for (intj = 0; j < GroupResult.group.groupUsers.userId.Length; j++)

{

Console.WriteLine("userID: "+ GroupResult.group.groupUsers.userId[j]);

}

 

 

Hope this helps!

Kevin

Click "Accept as Solution" if your problem is solved. To give thanks, click on the KUDOS STAR
Please use plain text.
New Contributor
mkoman
Posts: 5
Registered: ‎06-21-2011
My Carrier: developer

Re: How can I get user ids of a group?

Thank you for your help!

 

It seems that C# API return correctly group users but Java API return null :smileysad:


Becaouse I'm trying to get group users and their ids in similary way.

Please use plain text.
Developer
Developer
KPK
Posts: 18
Registered: ‎06-01-2011
My Carrier: Rogers

Re: How can I get user ids of a group?

When you did the search for the group did you include directusers?

 

boolean loadGroupDirectUsers=true;

FindGroupsResult  result= coreWebService.getGroup(groupId, locale,loadGroupDirectUsers);



 

 

Click "Accept as Solution" if your problem is solved. To give thanks, click on the KUDOS STAR
Please use plain text.
New Contributor
mkoman
Posts: 5
Registered: ‎06-21-2011
My Carrier: developer

Re: How can I get user ids of a group?

I didn't use search for the group by ID...

 

I found all groups by a method:

FindGroupsResult result = coreWebService.findGroups(organizationId, "en_US");

 

I used an iterator :

for (Group itr:result.getGroups()) {}

 

By the name i found a group I need:

String resultGroupName = itr.getLocaleNameAndDescription().get(0).getName();

if(resultGroupName.equals(groupName)) {}

 

And now I want to get users IDs in this group but the object is NULL:

GroupUsers groupUsers = itr.getGroupUsers();

Please use plain text.
Developer
Developer
KPK
Posts: 18
Registered: ‎06-01-2011
My Carrier: Rogers

Re: How can I get user ids of a group?

Maybe, now that you have found the group, use its ID to do the getgroup again.  That should return all the properties of the single group.

 

int groupID = ?

boolean loadGroupChildGroups=true;
boolean loadGroupParentGroups=true;

boolean loadGroupDirectUsers=true;

boolean loadGroupDirectAssignments=true;
GetGroupResult result = coreWebService.getGroup(groupId, locale, loadGroupChildGroups, loadGroupParentGroups, loadGroupDirectUsers, loadGroupDirectAssignments);

Then you can see any child groups by doing the following:

 

System.out.println("Child Groups: ");
for(Group itr:group.getGroupChildGroups().getGroup()){
   
System.out.print(itr.getGroupId()+" ");
}

 

You should be able to do the same loop to look for members of the group.

Maybe:

System.out.println("Users: ");
for(Group itr:group.getGroupDirectUsers().getGroupUsers()){
   
System.out.print(itr.getUserId()+" ");
}

 



Sorry, I'm just guessing here because I don't have a Java compiler.



Click "Accept as Solution" if your problem is solved. To give thanks, click on the KUDOS STAR
Please use plain text.
New Contributor
mkoman
Posts: 5
Registered: ‎06-21-2011
My Carrier: developer

Re: How can I get user ids of a group?

Thank you, it helped me, the problem is solved.

Please use plain text.
Developer
Developer
KPK
Posts: 18
Registered: ‎06-01-2011
My Carrier: Rogers

Re: How can I get user ids of a group?

Glad to hear that.

Happy to help.

 

Click "Accept as Solution" if your problem is solved. To give thanks, click on the KUDOS STAR
Please use plain text.