# Generate unique samaccountname for AD source

**URL:** <https://developer.sailpoint.com/discuss/t/generate-unique-samaccountname-for-ad-source/2529>\
**Category:** SHF Discussion and Questions\
**Created:** [December 31, 2021, 11:09am UTC](https://developer.sailpoint.com/discuss/t/generate-unique-samaccountname-for-ad-source/2529 "2021-12-31T11:09:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpoddar123](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mpoddar123](https://developer.sailpoint.com/discuss/u/mpoddar123)\
**Post date:** [December 31, 2021, 11:09am UTC](https://developer.sailpoint.com/discuss/t/generate-unique-samaccountname-for-ad-source/2529/1 "2021-12-31T11:09:16Z")

</div>

Hi,  
We need to generate unique samaccountname using rule for AD source. For uniqueness I want to use the below sample code for identity now but not getting how to modify it for identitynow instead of identityiq.

public boolean isUnique ( String username ) throws GeneralException {  
QueryOptions ops = new QueryOptions();  
ops.addFilter( Filter.ignoreCase( Filter.eq( “uid”, username ) ) );  
ops.addFilter( Filter.eq( “application”, application ) );  
int numberFound = context.countObjects( Link.class, ops );  
return numberFound == 0;  
}

Here the application filter needs to replaced with source filter. Kindly let me know how to do this.

Regards,  
Mahesh

---

<div class="post-metadata">

**Author:** ![menno\_pieters](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/menno_pieters/32/66_2.png) [@menno\_pieters](https://developer.sailpoint.com/discuss/u/menno_pieters)\
**Post date:** [January 6, 2022, 7:40am UTC](https://developer.sailpoint.com/discuss/t/generate-unique-samaccountname-for-ad-source/2529/2 "2022-01-06T07:40:10Z")

</div>

Hi,  
IdentityNow has built-in mechanisms in the transforms or via the UI using a generator, to create unique account names. See [IdentityNow Transforms - Username Generator - Compass](https://community.sailpoint.com/t5/IdentityNow-Wiki/IdentityNow-Transforms-Username-Generator/ta-p/180577)

Your code example assumes that accounts are never deleted. If that is true, it should be OK, but otherwise you could run into issues. Let’s say you have “user”, “user1”, “user2”, “user3”. User 1 leaves the organization and their account gets removed leaving “user”, “user2”, “user3”. When a new user comes, with the same base user name, the code would once again generate the account name “user3”.

- Menno

---

<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 19, 2023, 2:22pm UTC](https://developer.sailpoint.com/discuss/t/generate-unique-samaccountname-for-ad-source/2529/3 "2023-07-19T14:22:25Z")

</div>

Closed on July 19, 2023, 2:22pm UTC


