Adding bulk users to workgroup

Which IIQ version are you inquiring about?

Version 8.3

Share all details related to your problem, including any error messages you may have received.

Hi,

Can anyone suggest how do we add bulk users to workgroup members. Do we have any method like setworkgroupmembers(). If so please share us the sample code.
Any suggestions will be really helpfull.

Thanks!

@Preethi

If you list of Identities and the workGroup Name , please use below method to achieve the same

Fetch your WorkGroup Object and add to your Identity Object using identityObj.add(Identity workgroup);

save your Identity Object and commit the transaction

I am working on communityRestAPI plugin which should be available in the colab within few days - I can add this method there so you would be able to do that via webservice.

3 Likes

Below is simple Rule you can use, assuming you have the workgroup Name and List of names of identities to be added to the workgroup

  import sailpoint.api.IncrementalObjectIterator;

  import sailpoint.object.Identity;
  import sailpoint.object.QueryOptions;

  import sailpoint.object.Filter;




  import sailpoint.tools.Util;

  import java.util.List;

  import java.util.ArrayList;




  String workGroupName="<Your WorkGroup Name>";


  List userNames=new ArrayList();
  
// Make Sure you add the list of users to the above list of userNames

  QueryOptions qo = new QueryOptions();

  qo.addFilter(Filter.in("name", userNames));

  int recordCounter=0;


  IncrementalObjectIterator it = new IncrementalObjectIterator(context, Identity.class, qo);

  Identity workGroupObject=context.getObjectByName(Identity.class,workGroupName);

  while ( (it != null) &amp;&amp; (it.hasNext()) ) {
    recordCounter++;


    Identity identity = (Identity) it.next();


    identity.add(workGroupObject);
    context.saveObject(identity);

    if (0 == (recordCounter % 10)) {
      context.commitTransaction();
      context.decache();
    } 



  }

  context.commitTransaction();
  context.decache();

  Util.flushIterator(it);

  return "Success";

+ on Satish

If you have more than 2100 users then you will face below issue.

Solved: Filter.in Query doesn’t support more than 2100 items - Compass (sailpoint.com)

If you have such case then try
`
import com.google.common.colect.Lists;

List usersLists = Lists.partition(userNames, 2000);
for (List users : usersLists ) {
// do your filter and operation here
QueryOptions …
.
.
.
Util.flushIterator(it);
}

`

1 Like

Thanks Satish! working as expected…

Glad it worked, if you are using above code with more users , follow as Pravin mentioned or you can use below one as you have username directly, fetch the Identity object within the loop itself

for(String userName: userNames){

    Identity identity = context.getObjectByName(Identity.class, userName);

// Rest of the code


}
1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.