# Adding bulk users to workgroup

**URL:** <https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668>\
**Category:** IIQ Discussion and Questions\
**Tags:** identityiq\
**Created:** [May 15, 2024, 7:33pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668 "2024-05-15T19:33:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Preethi](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@Preethi](https://developer.sailpoint.com/discuss/u/Preethi)\
**Post date:** [May 15, 2024, 7:33pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/1 "2024-05-15T19:33:59Z")

</div>

### 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!

---

<div class="post-metadata">

**Author:** ![iamksatish](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/iamksatish/32/26217_2.png) [@iamksatish](https://developer.sailpoint.com/discuss/u/iamksatish)\
**Post date:** [May 15, 2024, 7:42pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/2 "2024-05-15T19:42:55Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![kjakubiak](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kjakubiak/32/7052_2.png) [@kjakubiak](https://developer.sailpoint.com/discuss/u/kjakubiak)\
**Post date:** [May 15, 2024, 7:48pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/3 "2024-05-15T19:48:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iamksatish](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/iamksatish/32/26217_2.png) [@iamksatish](https://developer.sailpoint.com/discuss/u/iamksatish)\
**Post date:** [May 15, 2024, 7:58pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/4 "2024-05-15T19:58:36Z")

</div>

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

```auto
  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";

```

---

<div class="post-metadata">

**Author:** ![pravin\_ranjan](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/pravin_ranjan/32/6771_2.png) [@pravin\_ranjan](https://developer.sailpoint.com/discuss/u/pravin_ranjan)\
**Post date:** [May 15, 2024, 10:03pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/5 "2024-05-15T22:03:01Z")

</div>

`+ 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)](https://community.sailpoint.com/t5/IdentityIQ-Forum/Filter-in-Query-doesn-t-support-more-than-2100-items/m-p/147644)

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

`

---

<div class="post-metadata">

**Author:** ![Preethi](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@Preethi](https://developer.sailpoint.com/discuss/u/Preethi)\
**Post date:** [May 15, 2024, 10:03pm UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/6 "2024-05-15T22:03:06Z")

</div>

Thanks Satish! working as expected…

---

<div class="post-metadata">

**Author:** ![iamksatish](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/iamksatish/32/26217_2.png) [@iamksatish](https://developer.sailpoint.com/discuss/u/iamksatish)\
**Post date:** [May 16, 2024, 2:41am UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/7 "2024-05-16T02:41:30Z")

</div>

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

```auto
for(String userName: userNames){

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

// Rest of the code

}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 15, 2024, 2:41am UTC](https://developer.sailpoint.com/discuss/t/adding-bulk-users-to-workgroup/56668/8 "2024-07-15T02:41:37Z")

</div>

Closed on July 15, 2024, 2:41am UTC

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