Skip to Content
avatar image
Former Member

Add users to a group through programming

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Aug 17, 2007 at 02:49 PM
    Add comment
    10|10000 characters needed characters exceeded

  • Aug 17, 2007 at 03:36 PM

    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)");

    }

    }

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 17, 2007 at 08:21 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 13, 2011 at 04:39 PM

    Solved

    Add comment
    10|10000 characters needed characters exceeded