# Best practice for setting identity attributes through code

**URL:** <https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829>\
**Category:** IIQ Discussion and Questions\
**Tags:** workflows, rules, identityiq, apis\
**Created:** [August 13, 2026, 5:48am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829 "2026-08-13T05:48:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishavghoshacc](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@rishavghoshacc](https://developer.sailpoint.com/discuss/u/rishavghoshacc)\
**Post date:** [August 13, 2026, 5:48am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/1 "2026-08-13T05:48:47Z")

</div>

Hi all,

What is the best way to iterate over all identities and set an attribute through a Beanshell rule in IIQ

Can someone help me with the code as well.

Currently I doing the below:

1. Using incrementaliterator and flushing at the end
2. I am setting the attribute and saving using saveObject and commitTransaction

Is there anything that I need to add to this process.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![kumarSinghM](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kumarSinghM](https://developer.sailpoint.com/discuss/u/kumarSinghM)\
**Post date:** [August 13, 2026, 12:50pm UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/2 "2026-08-13T12:50:06Z")

</div>

Hi @rishavghoshacc

I have listed down some best practices:

- IncrementalObjectIterator is a good choice for processing all identities.
- Commit changes in batches of approximately 100–500 identities.
- Do not commit after every identity because that creates excessive database transactions.
- Do not wait until every identity is processed because the Hibernate cache and transaction can become very large.
- Call context.decache() after each batch commit to release cached Identity objects.
- Put Util.flushIterator() in a finally block so the database cursor is released even when an exception occurs.
- Use context.rollbackTransaction() when processing fails.
- Avoid saving identities whose attribute already has the required value.

---

<div class="post-metadata">

**Author:** ![Jerinhrb04](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jerinhrb04/32/42240_2.png) [@Jerinhrb04](https://developer.sailpoint.com/discuss/u/Jerinhrb04)\
**Post date:** [August 13, 2026, 1:02pm UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/3 "2026-08-13T13:02:09Z")

</div>

Your approach is generally correct. some additional recommendations from my side would be:

- Use an iterator to process identities one at a time instead of loading everything into memory.
- Save changes in small batches rather than after every identity.
- Clear cached objects periodically to keep memory usage low.
- Update only the identities that actually need a change.
- Add basic logging so you can track progress and identify failures.
- Handle exceptions properly and roll back changes if an error occurs.
- Test the rule on a small set of identities before running it against the entire population.

---

<div class="post-metadata">

**Author:** ![mlangerdz](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@mlangerdz](https://developer.sailpoint.com/discuss/u/mlangerdz)\
**Post date:** [August 13, 2026, 1:05pm UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/4 "2026-08-13T13:05:05Z")

</div>

Hi, here’s an example…

```auto
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.tools.Util;

int BATCH_SIZE = 50;
int processed = 0;
int updated = 0;
int pending = 0;

QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq("workgroup", new Boolean(false)));
qo.setOrderBy("name");

IncrementalObjectIterator it = null;

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

    while (it.hasNext()) {
        Identity identity = (Identity) it.next();
        processed++;

        String desired = "MY_VALUE"; // your logic here
        
        identity.setAttribute("myAttr", desired);
        context.saveObject(identity);
        updated++;
        pending++;

        if (pending >= BATCH_SIZE) {
            context.commitTransaction();
            context.decache(); // must come AFTER the commit
            pending = 0;
        }
    }

    if (pending > 0) {
        context.commitTransaction();
        context.decache();
    }
}
catch (Exception e) {
    context.rollbackTransaction();
    throw e;
}
finally {
    Util.flushIterator(it); // always release the cursor
}

return "processed=" + processed + ", updated=" + updated;

```

---

<div class="post-metadata">

**Author:** ![punna0001](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/punna0001/32/42011_2.png) [@punna0001](https://developer.sailpoint.com/discuss/u/punna0001)\
**Post date:** [August 14, 2026, 2:41am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/5 "2026-08-14T02:41:47Z")

</div>

Hello Rishav. The iterator approach you have looks right for a bulk update. One additional thing I would check before running it is whether this attribute has a source configured under Global Settings → Identity Mappings.

If the attribute is derived from an Application Attribute, Application Rule, or Global Rule, I would first confirm whether updating it directly is the intended design. IIQ uses those source mappings to derive identity attribute values, and Refresh identity attributes can update the Identity Cube based on those mappings.

If the value itself should be calculated by IIQ, it may be cleaner to implement that logic in the appropriate identity source mapping and let the normal aggregation/refresh processing maintain it.

If this is simply a custom identity attribute that you intentionally maintain through code and it has no source mapping that will recalculate it, then the batched `IncrementalObjectIterator` approach suggested above should be a good fit.

---

<div class="post-metadata">

**Author:** ![mkumariaas](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/mkumariaas/32/40387_2.png) [@mkumariaas](https://developer.sailpoint.com/discuss/u/mkumariaas)\
**Post date:** [August 14, 2026, 4:50am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/6 "2026-08-14T04:50:58Z")

</div>

> [@punna0001](#):
>
> `IncrementalObjectIterator`

hi @rishavghoshacc please check below article, it will give you more idea on this. Also please use decache after every 50 or 100 record.  
Generally if you are saving also then sailpoint recommend to lock the identity object and then save and then unlock. If lock then wait for some time.  
Check this community Page [SailPoint Compass Community](https://community.sailpoint.com/t5/Technical-White-Papers/BSDG-20-Locking-Identity-Objects-for-Modification/ta-p/76456)

> **[SailPoint Compass Community](https://community.sailpoint.com/)**
>
> SailPoint Community is being migrated. Find updated resources and helpful links during this transition.

---

<div class="post-metadata">

**Author:** ![neel193](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/neel193/32/34038_2.png) [@neel193](https://developer.sailpoint.com/discuss/u/neel193)\
**Post date:** [August 24, 2026, 5:51pm UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/7 "2026-08-24T17:51:19Z")

</div>

@rishavghoshacc What attribute are you setting? For one of the project, we did this using IdentityRefresh prerefresh rule.. You can create a population and assign to the task on which you need to set the attributes, then just use setAttribute to set the value.. no need to iterate or saveObject or commit transaction, and don’t return any thing. just do setAttribute that’s it..

Another advantage is, as it is refresh it can be partitioned to sped up the execution.

---

<div class="post-metadata">

**Author:** ![rishavghoshacc](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@rishavghoshacc](https://developer.sailpoint.com/discuss/u/rishavghoshacc)\
**Post date:** [September 2, 2026, 6:51am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/8 "2026-09-02T06:51:09Z")

</div>

@neel193 Where can I find the prerefresh rule?

---

<div class="post-metadata">

**Author:** ![neel193](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/neel193/32/34038_2.png) [@neel193](https://developer.sailpoint.com/discuss/u/neel193)\
**Post date:** [September 2, 2026, 7:52am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/9 "2026-09-02T07:52:31Z")

</div>

@rishavghoshacc Please check this article: [Rules in IdentityIQ - Compass](https://community.sailpoint.com/t5/Technical-White-Papers/Rules-in-IdentityIQ/ta-p/78176). Check Page no. 44 for the sample.

---

<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:** [November 1, 2026, 7:53am UTC](https://developer.sailpoint.com/discuss/t/best-practice-for-setting-identity-attributes-through-code/218829/10 "2026-11-01T07:53:11Z")

</div>

Closed on November 1, 2026, 7:53am UTC

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