cancel
Showing results for 
Search instead for 
Did you mean: 

Add users to a group through programming

Former Member
0 Kudos

Hi,

I would like to achieve a bit of programming that allows me to add a user to a group rather than straight to a role.

Has anyone been able to do this before or can anyone help.

I would gratefully appreciate it and will reward points.

Thanks

Kai

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Solved

Former Member
0 Kudos

Kai,

its pretty simple. Try the following code:

I hope you have your user object whom you want to add to the group. I am just creating a user object for showing it - then obtaining the group also for simplicity. You would know better how would you find out the user object & the group object.

IUserFactory userFact = UMFactory.getUserFactory();
IGroupFactory groupFact = UMFactory.getGroupFactory();
    	
  	try {
		//obtain the user object
		IUser user = userFact.getUserByLogonID("YOUR USER ID");
		//get the unique id of the user
		String userUniqueId = user.getUniqueID();
		//obtain the group object
		IGroup group = groupFact.getGroupByUniqueName("GROUP NAME");
		//get the group unique id
		String groupUniqueId = group.getUniqueID();
		//assign the user to the group via GroupFactory
		groupFact.addUserToGroup(userUniqueId, groupUniqueId);
			
	} catch (UMException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	});

And you are done!!!

Regards,

Shubhadip

Message was edited by:

Shubhadip Ghosh

former_member189428
Contributor
0 Kudos

hi Kai Chalker

try this

IGroup getSingleGroup(String searchStr, boolean fuzzy) throws UMException {

IGroupFactory gFact = UMFactory.getGroupFactory();

IGroupSearchFilter gsf = gFact.getGroupSearchFilter();

if (fuzzy) {

gsf.setDisplayName("" + searchStr + "",

ISearchAttribute.LIKE_OPERATOR,false);

} else {

gsf.setDisplayName(searchStr,

ISearchAttribute.EQUALS_OPERATOR,false);

}

ISearchResult sr = gFact.searchGroups(gsf);

if (sr.size() == 0)

throw new UMException("Role: " + searchStr + " not found");

if (sr.size() == 1)

return gFact.getGroup((String) sr.next());

else

throw new UMException("Group: "+ searchStr +

" not unique (found "+ sr.size()+ " matches)");

}

}

Former Member
0 Kudos