Get users of group (Engine API)

Hi all,
i would like to get the list of users from a specific group and assign it to a java object variable.

the script below works in the deprecated version of groovy script but i would like to get it running in the current version:
import org.bonitasoft.engine.identity.UserCriterion;
import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.User;

IdentityAPI ia = apiAccessor.getIdentityAPI();
List userlist = ia.getUsersInGroup(ia.getGroupByPath(“/organisation/group”).getId(), 0, 100, UserCriterion.LAST_NAME_ASC);
List usernames = new ArrayList();
for(User u:userlist){
usernames.add(u.getUserName());
}
return usernames;

The wiki provides an example, but how can I get the GroupID?

final IdentityAPI identityAPI = TenantAPIAccessor.getIdentityAPI(apiSession);
final SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 100);
builder.filter(UserSearchDescriptor.GROUP_ID, groupID);
final SearchResult userResults = identityAPI(apiSession).searchUsers(builder.done());

3 Likes