# Attribute Generator Rule - Unique ID Creation

**URL:** <https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876>\
**Category:** SHF Discussion and Questions\
**Tags:** identity-security-cloud, rules\
**Created:** [March 19, 2025, 8:03pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876 "2025-03-19T20:03:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnjanaAK](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@AnjanaAK](https://developer.sailpoint.com/discuss/u/AnjanaAK)\
**Post date:** [March 19, 2025, 8:03pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/1 "2025-03-19T20:03:46Z")

</div>

Hi All,  
I am trying to build an attribute generator rule to populate value for an attribute called Abbrev during provisioning. I validated the below code and it does not check for unique values and creates the same value for all the identities with the same name.

Example:  
Doe, John  
This code generates Doe, J for all the users with same name failing to check the uniqueness instead of following the logic in the code, I have used “attrSearchCountAccounts” to check the uniqueness.  
Kindly let me know if there is any issue with the code.

Thanks All.

```auto
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
import sailpoint.object.Application;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;
import sailpoint.rule.*;

List sourceIDList = new ArrayList(Arrays.asList(new String[]{"....."}));
String abbrev="";

String firstName = StringUtils.trimToNull(identity.getAttribute("firstname"));
String lastName = StringUtils.trimToNull (identity.getAttribute("lastname"));
String middleName = StringUtils.trimToNull (identity.getAttribute ("midddleName"));
String firstchar = StringUtils.substring(firstName, 0, 1);
String middlechar = StringUtils.substring(middleName, 0, 1);
public boolean isUnique(String abbrev){
	String operation = "Equals";
	boolean isUnique = false;
	List searchValues = new ArrayList(Arrays.asList (new String[] {abbrev}));
	if(idn.attrSearchCountAccounts(sourceIDList, "allAbbrev", operation, searchValues) == 0) {
		isUnique = true;
	}else{
		isUnique = false;
	}
	return isUnique;
}

public String createUniqueID(String abbrev) throws Exception{
	long uniqueCounter = 1;
	String tempAbbrev = abbrev + new String(uniqueCounter);
	while(!isUnique(tempAbbrev) && uniqueCounter < 20){
		uniqueCounter++;
		tempAbbrev = abbrev + new String(uniqueCounter);
	}
	if(uniqueCounter >= 20){
		throw new Exception("Unique Name counter exceeds max limit");
	}
	
	return tempAbbrev;
}
if(firstName == null || "".equals(firstName) || lastName == null || "".equals(lastName)){
	throw new Exception("First Name or Last Name is null or empty");
}else{
	abbrev = lastName + ", " + firstchar;
	if(!isUnique(abbrev)){
		abbrev = lastName + ", " + firstName;
		if(!isUnique(abbrev)){
			if(middleName == null || "".equals(middleName)){
				throw new Exception("Middle Name is null or empty");
			}else{
				abbrev = lastName + ", " + firstName + ", " + middlechar;
				if(!isUnique(abbrev)){
					abbrev = lastName + ", " + firstName + ", " + middleName;
					if(!isUnique(abbrev)){
						abbrev = createUniqueID(abbrev);
					}
				}
			}
		}
		return abbrev;
	}else{
		return abbrev;
	}
}

```

---

<div class="post-metadata">

**Author:** ![KRM7](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/krm7/32/2685_2.png) [@KRM7](https://developer.sailpoint.com/discuss/u/KRM7)\
**Post date:** [March 19, 2025, 10:26pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/2 "2025-03-19T22:26:12Z")

</div>

Before checking the Rule, did you consider Generators for your requirement

---

<div class="post-metadata">

**Author:** ![JackSparrow](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jacksparrow/32/19685_2.png) [@JackSparrow](https://developer.sailpoint.com/discuss/u/JackSparrow)\
**Post date:** [March 20, 2025, 4:42am UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/3 "2025-03-20T04:42:41Z")

</div>

Hi @AnjanaAK ,

I do see you have sourceIDList, but not adding any sourceIDs to it and you are using it in “isUnique” method. Thus, this method is not returning anything and failing to check uniqueness

```auto
List sourceIDList = new ArrayList(Arrays.asList(new String[]{"....."}))

```

```auto
if(idn.attrSearchCountAccounts(sourceIDList, "allAbbrev", operation, searchValues) == 0)

```

You can get the sourceID using `String sourceID = application.getID();` and then add it to the sourceIDList using `sourceIDList.add(sourceID)`;

---

<div class="post-metadata">

**Author:** ![AnjanaAK](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@AnjanaAK](https://developer.sailpoint.com/discuss/u/AnjanaAK)\
**Post date:** [March 20, 2025, 1:14pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/4 "2025-03-20T13:14:07Z")

</div>

Hi,  
I did, but we need to implement multiple “IF ELSE” conditions so I thought rule must the way to go about it.  
Example:  
(First name + ", " + Last name’s first letter)  
If not unique  
(First name + ", " + Last name)  
If not unique  
(First name + ", " + Last name + ", " + Middle name’s first letter)  
If not unique  
(First name + ", " + Last name + ", " + Middle name)  
If not unique  
(First name + ", " + Last name + ", " + Middle name + counter

So I am trying to write a rule for the above conditions

---

<div class="post-metadata">

**Author:** ![AnjanaAK](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@AnjanaAK](https://developer.sailpoint.com/discuss/u/AnjanaAK)\
**Post date:** [March 20, 2025, 1:18pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/5 "2025-03-20T13:18:50Z")

</div>

Hi,  
I removed the source ID while posting the code in the community. But while deploying the code it was sent along with the source ID

---

<div class="post-metadata">

**Author:** ![KRM7](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/krm7/32/2685_2.png) [@KRM7](https://developer.sailpoint.com/discuss/u/KRM7)\
**Post date:** [March 20, 2025, 1:25pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/6 "2025-03-20T13:25:26Z")

</div>

You should check this [Username Generator Transform](https://developer.sailpoint.com/docs/extensibility/transforms/operations/username-generator)

 ![image](https://global.discourse-cdn.com/sailpoint/original/3X/e/9/e986514330f687904b5a59975788c826b997f42e.png)

---

<div class="post-metadata">

**Author:** ![JackSparrow](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jacksparrow/32/19685_2.png) [@JackSparrow](https://developer.sailpoint.com/discuss/u/JackSparrow)\
**Post date:** [March 20, 2025, 1:41pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/7 "2025-03-20T13:41:02Z")

</div>

Then I would suggest printing the count value to see if it’s actually give the output

```auto
int count = idn.attrSearchCountAccounts(sourceIDList, "allAbbrev", operation, searchValues)
System.out.println("count: " + count);

```

---

<div class="post-metadata">

**Author:** ![AnjanaAK](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@AnjanaAK](https://developer.sailpoint.com/discuss/u/AnjanaAK)\
**Post date:** [March 20, 2025, 3:41pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/8 "2025-03-20T15:41:04Z")

</div>

I checked this, but it is mentioned that this transform can be used only for attributes that are marked as AccountID in the account schema

 ![image](https://global.discourse-cdn.com/sailpoint/original/3X/6/4/646d52a7f2450ea976a1dccbedafbe69c8574ba3.png)

---

<div class="post-metadata">

**Author:** ![AnjanaAK](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@AnjanaAK](https://developer.sailpoint.com/discuss/u/AnjanaAK)\
**Post date:** [March 20, 2025, 3:42pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/9 "2025-03-20T15:42:01Z")

</div>

It is a cloud rule, is there any way this could be checked. I tired using rule validator and Rule Development Kit none of which checks sailpoint functionalities.

---

<div class="post-metadata">

**Author:** ![JackSparrow](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jacksparrow/32/19685_2.png) [@JackSparrow](https://developer.sailpoint.com/discuss/u/JackSparrow)\
**Post date:** [March 20, 2025, 4:23pm UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/10 "2025-03-20T16:23:35Z")

</div>

Nope, we need to raise support case to get the logs.

---

<div class="post-metadata">

**Author:** ![RAKRHEEM](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@RAKRHEEM](https://developer.sailpoint.com/discuss/u/RAKRHEEM)\
**Post date:** [March 24, 2025, 11:20am UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/11 "2025-03-24T11:20:21Z")

</div>

Hi Anjana,  
Please have the configuration like this in the Provisioning Policy.  
{  
“name”: “accountAttribute”,  
“transform”: {  
“type”: “rule”,  
“attributes”: {  
“name”: “Your Rule Name”  
}  
},  
“attributes”: {  
“sourceCheck”: true  
},  
“isRequired”: false,  
“type”: “string”,  
“isMultiValued”: false  
}

---

<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:** [May 23, 2025, 11:20am UTC](https://developer.sailpoint.com/discuss/t/attribute-generator-rule-unique-id-creation/104876/12 "2025-05-23T11:20:34Z")

</div>

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