# sAMAccountName Generator

**URL:** <https://developer.sailpoint.com/discuss/t/samaccountname-generator/820>\
**Category:** SHF Discussion and Questions\
**Created:** [June 23, 2021, 1:16pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820 "2021-06-23T13:16:53Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgomez](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dgomez](https://developer.sailpoint.com/discuss/u/dgomez)\
**Post date:** [June 23, 2021, 1:16pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/1 "2021-06-23T13:16:53Z")

</div>

Hello,

I am trying to use the below code for generating a sAMAccountName, for some reason it keeps erroring out in IdentityNow, I followed some guidance provided in: [IdentityNow Transforms - Username Generator - Compass](https://community.sailpoint.com/t5/IdentityNow-Wiki/IdentityNow-Transforms-Username-Generator/ta-p/180577)

But it is still failing on this attribute, any recommendations?

```auto
{

                "attributes": {

                    "cloudMaxSize": "100",

                    "cloudMaxUniqueChecks": "5",

                    "cloudRequired": "true"

                },

                "isRequired": false,

                "multi": false,

                "name": "sAMAccountName",

                "transform": {

                    "attributes": {

                        "fi": {

                            "attributes": {

                                "begin": 0,

                                "end": 1,

                                "input": {

                                    "attributes": {

                                        "name": "firstname"

                                    },

                                    "type": "identityAttribute"

                                }

                            },

                            "type": "substring"

                        },

                        "fn": {

                            "attributes": {

                                "name": "firstname"

                            },

                            "type": "identityAttribute"

                        },

                        "ln": {

                            "attributes": {

                                "input": {

                                    "attributes": {

                                        "name": "lastname"

                                    },

                                    "type": "identityAttribute"

                                }

                            },

                            "type": "upper"

                        },

                        "mi": {

                            "attributes": {

                                "begin": 0,

                                "end": 1,

                                "input": {

                                    "attributes": {

                                        "name": "middleName"

                                    },

                                    "type": "identityAttribute"

                                }

                            },

                            "type": "substring"

                        },

                        "patterns": [

                            "$fi.$ln",

                            "$fn.$mi.$ln",

                            "$fn.$mi.$ln${uniqueCounter}"

                        ],

                        "sourceCheck": true

                    },

                    "type": "usernameGenerator"

                },

                "type": ""

            },

```

---

<div class="post-metadata">

**Author:** ![dgomez](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dgomez](https://developer.sailpoint.com/discuss/u/dgomez)\
**Post date:** [June 23, 2021, 1:22pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/2 "2021-06-23T13:22:59Z")

</div>

The error received:

sailpoint.tools.GeneralException: Error generating account username for identity: \*\*\*\*\*\*\*\*\*\*, appName: \*\*\*\*\*\*\*\*\*\* Exception error msg: Error rendering template: $fn.$mi.$ln at sailpoint.server.ScriptletEvaluator.doCall(ScriptletEvaluator.java:175)

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 23, 2021, 1:38pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/3 "2021-06-23T13:38:39Z")

</div>

Just looking at the JSON you shared, there might be a typo in your middle name attribute. Your `firstname` and `lastname` attributes are all lower case, but your `middleName` attribute is camel case. Is that correct, or should middle name also be all lower case? That could explain why the generator fails on the second pattern and not the first, since the second pattern introduces the middle name attribute.

---

<div class="post-metadata">

**Author:** ![dgomez](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dgomez](https://developer.sailpoint.com/discuss/u/dgomez)\
**Post date:** [June 23, 2021, 1:51pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/4 "2021-06-23T13:51:01Z")

</div>

Hi Colin,

Thank you for your response, the technical name for Middle Name is correct, I created that attribute in the Identity Profile and used the generated camel case.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 23, 2021, 1:55pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/5 "2021-06-23T13:55:50Z")

</div>

Hmm. I still have a hunch it has something to do with the middle name attribute, since it fails on that pattern. Could you try the following?

1. Remove all patterns except for $fi.$ln and see if that is successful? That will tell us if the JSON at least works for first/last name.
2. Remove the substring logic from the middle name attribute to see if that is causing the error. If the error goes away, then it must have something to do with the substring.

---

<div class="post-metadata">

**Author:** ![dgomez](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dgomez](https://developer.sailpoint.com/discuss/u/dgomez)\
**Post date:** [June 23, 2021, 2:55pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/6 "2021-06-23T14:55:18Z")

</div>

Still provides an error, but a slightly different one this time:

Stopped processing username creation for pattern: $fn.$ln${uniqueCounter} because maximum attempts reached: 5

This would bring two questions:

- There should be no collision as nobody else exists with this same firstName (checked), why would the counter increase in this case?
- Why would the middle name be the cause for the initial fail? When it has the same logic as the first name.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 23, 2021, 5:37pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/7 "2021-06-23T17:37:23Z")

</div>

It actually might be your $fn variable. I didn’t realize you had a first initial ($fi) and first name ($fn). You can verify it is not the $mi by doing a pattern like `$fi.$mi.$ln`. If that succeeds, then there is something going in with your first name ($fn) variable.

As to why the counter increased, I’m not sure. While you validate that it is not the $mi variable and just the $fn variable causing issues, I’ll ask around internally to see if someone can shed some light on this.

---

<div class="post-metadata">

**Author:** ![lisa\_ivy](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@lisa\_ivy](https://developer.sailpoint.com/discuss/u/lisa_ivy)\
**Post date:** [June 24, 2021, 12:58pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/8 "2021-06-24T12:58:59Z")

</div>

The code looks correct to me - I compared it to a usernameGenerator attribute I’m using in a create profile, and the only difference is that instead of “multi”: false, I have “isMultiValued”: false – but I believe both formats are acceptable. Are you testing with a user who has a first name, middle name, and last name populated?

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 28, 2021, 5:42pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/9 "2021-06-28T17:42:28Z")

</div>

Hey @dgomez,

I wanted to check in and see if the above was able to be of any help for you. We would love to hear an update and please let us know if we can be of any further assistance to you!

---

<div class="post-metadata">

**Author:** ![dgomez](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dgomez](https://developer.sailpoint.com/discuss/u/dgomez)\
**Post date:** [June 29, 2021, 12:23pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/10 "2021-06-29T12:23:56Z")

</div>

Hi,

I still get the same error, I have changed the code to slightly different variations and it still drops the same error:

error msg: Stopped processing username creation for pattern: $fi.$ln${uniqueCounter} because maximum attempts reached: 10 (I increased the checks, even thought thre shouldn’t be a duplicate).

The simplified code:

```auto
           {
                "attributes": {
                    "cloudMaxSize": "100",
                    "cloudMaxUniqueChecks": "10",
                    "cloudRequired": "true"
                },
                "isRequired": false,
                "isMultiValued": false,
                "name": "sAMAccountName",
                "transform": {
                    "attributes": {
                        "fi": {
                            "attributes": {
                                "begin": 0,
                                "end": 1,
                                "input": {
                                    "attributes": {
                                        "name": "firstname"
                                    },
                                    "type": "identityAttribute"
                                }
                            },
                            "type": "substring"
                        },
                        "fn": {
                            "attributes": {
                                "input": {
                                    "attributes": {
                                        "name": "firstname"
                                    },
                                    "type": "identityAttribute"
                                }
                            },
                            "type": "upper"
                        },
                        "ln": {
                            "attributes": {
                                "input": {
                                    "attributes": {
                                        "name": "lastname"
                                    },
                                    "type": "identityAttribute"
                                }
                            },
                            "type": "upper"
                        },
                        "patterns": [
                            "$fi.$ln",
                            "$fi.$ln${uniqueCounter}"
                        ],
                        "sourceCheck": true
                    },
                    "type": "usernameGenerator"
                },
                "type": ""
            },

```

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 29, 2021, 3:18pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/11 "2021-06-29T15:18:14Z")

</div>

Hey @dgomez,

Your code looked good upon review. Above, Lisa asks if you have all of the attributes populated (i.e. are you testing with a user with a first, middle, and last name populated)? Could this be the issue?

---

<div class="post-metadata">

**Author:** ![dgomez](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dgomez](https://developer.sailpoint.com/discuss/u/dgomez)\
**Post date:** [June 29, 2021, 3:24pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/12 "2021-06-29T15:24:55Z")

</div>

That’s correct, all these attributes are populated in my test cases.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 29, 2021, 7:01pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/13 "2021-06-29T19:01:04Z")

</div>

Hey @dgomez,

Thanks for the prompt reply. I am sorry the above was not able to resolve the issue.  
Given the facts in this case, we should likely escalate your issue and file a [support ticket](https://support.sailpoint.com/hc/en-us/requests/new). The support team are going to be the best folks for helping you with diving into specifics, debugging, and to having your issue investigated more closely.

Please let me know if you encounter any issues filing a a ticket and I would be glad to assist you further.

Regards,

Michael Ellis  
Developer Community Manager

---

<div class="post-metadata">

**Author:** ![chrisp](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chrisp](https://developer.sailpoint.com/discuss/u/chrisp)\
**Post date:** [October 28, 2021, 7:10pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/14 "2021-10-28T19:10:24Z")

</div>

Has anyone been able to generate a sAMAccountName using the usernameGenerator transform?

I found a different topic where is was mentioned that this could only be used for the account ID for a source, and for AD that is the distinguishedName.

> [@usernameGenerator Transform](https://developer.sailpoint.com/discuss/t/usernamegenerator-transform/1404):
>
> Hello, Can we use “usernameGenerator” type transform to generate the unique value for any attribute like userPrincipalName, mail that’s present on the “create profile” page, or are there any limitations on the attribute on which we can use that type of transform? Thanks, Sushant

Check the solution by lisa.ivy.

We have a need to generate the DN and the sAMAccountName, with different patters, and using the uniqueCounter. Can we use the usernameGenerator transform for both attributes?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![Sushant](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Sushant](https://developer.sailpoint.com/discuss/u/Sushant)\
**Post date:** [November 3, 2021, 5:10pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/15 "2021-11-03T17:10:10Z")

</div>

Hi @chrisp,

I tried the “usernameGenerator” transform for attributes other than Account ID and it didn’t work for me. It only works for the Account ID. If you want to generate a unique sAMAccountName using different patterns then I believe you will need to leverage the “AttributeGenerator” rule.

Thanks,  
Sushant

---

<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:21pm UTC](https://developer.sailpoint.com/discuss/t/samaccountname-generator/820/16 "2023-07-19T14:21:53Z")

</div>

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


