# usernameGenarator

**URL:** <https://developer.sailpoint.com/discuss/t/usernamegenarator/9753>\
**Category:** SHF Discussion and Questions\
**Created:** [March 28, 2023, 1:20pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753 "2023-03-28T13:20:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![reinajss](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/reinajss/32/12652_2.png) [@reinajss](https://developer.sailpoint.com/discuss/u/reinajss)\
**Post date:** [March 28, 2023, 1:20pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753/1 "2023-03-28T13:20:14Z")

</div>

Hi everyone,

I’m traing to create a transformation, using the example in the documentation for transform usernameGenerator: [Username Generator | SailPoint Developer Community](https://developer.sailpoint.com/idn/docs/transforms/operations/username-generator)  
The code examplo that I’m using:

```json
{
    "attributes": {
      "cloudMaxSize": "100",
      "cloudMaxUniqueChecks": "9",
      "cloudRequired": "true"
    },
    "isRequired": false,    
    "multi": false,
    "name": "criaEmailTerceiro",
    "transform": {
      "type": "usernameGenerator",
      "attributes": {
        "sourceCheck": true,
        "patterns": [
            "$terc$f1$ln@dominio.com.br",
            "$terc$f2$ln@dominio.com.br",
            "$terc$f1$f3$ln@dominio.com.br",
            "$terc$f2$f3$ln@dominio.com.br",
            "$terc$f1.$ln{uniqueCounter}@dominio.com.br"
        ],
        "f1": {
            "type": "lower",
            "attributes": {
                "input": {
                    "attributes": {
                        "begin": 0,
                        "end": 1,
                        "input": {
                            "type": "accountAttribute",
                            "attributes": {
                                "sourceName": "Base",
                                "attributeName": "NOME"
                            }
                        }
                    },
                    "type": "substring"
                }
            }
        },
        "f2": {
            "type": "lower",
            "attributes": {
                "input": {
                    "attributes": {
                        "begin": 0,
                        "end": 2,
                        "input": {
                            "type": "accountAttribute",
                            "attributes": {
                                "sourceName": "Base",
                                "attributeName": "NOME"
                            }
                        }
                    },
                    "type": "substring"
                }
            }
        },
        "f3": {
            "type": "lower",
            "attributes": {
                "input": {
                    "attributes": {
                        "begin": 0,
                        "end": 1,
                        "input": {
                            "type": "accountAttribute",
                            "attributes": {
                                "sourceName": "Base",
                                "attributeName": "NOME_DO_MEIO"
                            }
                        }
                    },
                    "type": "substring"
                }
            }
        },
        "ln": {
            "type": "lower",
            "attributes": {
                "input": {
                    "type": "accountAttribute",
                    "attributes": {
                        "sourceName": "Base",
                        "attributeName": "ULTIMO_SOBRENOME"
                    }
                }
            }
        },
        "terc": {
            "type": "static",
            "attributes": {
                "value": "terceiro-"
            }
        }
        }
    },
    "type": "usernameGenerator"
  }

```

But when I save it looks like this after I save the transformation:  
This is the code after that I saved:

```json
{
    "id": "For security I change this ID",
    "name": "criaEmailTerceiro",
    "type": "usernameGenerator",
    "attributes": {
        "cloudMaxSize": "100",
        "cloudMaxUniqueChecks": "9",
        "cloudRequired": "true"
    },
    "internal": false
}

```

Anybody could be help me to identify this problem and solve?

thank you very much in advance

---

<div class="post-metadata">

**Author:** ![tyler\_mairose](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tyler_mairose/32/30112_2.png) [@tyler\_mairose](https://developer.sailpoint.com/discuss/u/tyler_mairose)\
**Post date:** [March 28, 2023, 3:57pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753/2 "2023-03-28T15:57:49Z")

</div>

Hello @reinajss,

The transform looks valid.

The `usernameGenerator` transform is meant to be used during account creation, so it would be attached to an account create provisioning policy.

> **[create-provisioning-policy | SailPoint Developer Community](https://developer.sailpoint.com/idn/api/v3/create-provisioning-policy)**
>
> Create Provisioning Policy

The body of the request would look something like below

```json
{
  "name": "Account Creation Policy",
  "description": "Create Account Policy",
  "usageType": "CREATE",
  "fields": [
    {
      "attributes": {
        "cloudMaxSize": "100",
        "cloudMaxUniqueChecks": "9",
        "cloudRequired": "true"
      },
      "isRequired": false,
      "multi": false,
      "name": "criaEmailTerceiro",
      "transform": {
        "type": "usernameGenerator",
        "attributes": {
          "sourceCheck": true,
          "patterns": [
            "$terc$f1$ln@dominio.com.br",
            "$terc$f2$ln@dominio.com.br",
            "$terc$f1$f3$ln@dominio.com.br",
            "$terc$f2$f3$ln@dominio.com.br",
            "$terc$f1.$ln{uniqueCounter}@dominio.com.br"
          ],
          "f1": {
            "type": "lower",
            "attributes": {
              "input": {
                "attributes": {
                  "begin": 0,
                  "end": 1,
                  "input": {
                    "type": "accountAttribute",
                    "attributes": {
                      "sourceName": "Base",
                      "attributeName": "NOME"
                    }
                  }
                },
                "type": "substring"
              }
            }
          },
          "f2": {
            "type": "lower",
            "attributes": {
              "input": {
                "attributes": {
                  "begin": 0,
                  "end": 2,
                  "input": {
                    "type": "accountAttribute",
                    "attributes": {
                      "sourceName": "Base",
                      "attributeName": "NOME"
                    }
                  }
                },
                "type": "substring"
              }
            }
          },
          "f3": {
            "type": "lower",
            "attributes": {
              "input": {
                "attributes": {
                  "begin": 0,
                  "end": 1,
                  "input": {
                    "type": "accountAttribute",
                    "attributes": {
                      "sourceName": "Base",
                      "attributeName": "NOME_DO_MEIO"
                    }
                  }
                },
                "type": "substring"
              }
            }
          },
          "ln": {
            "type": "lower",
            "attributes": {
              "input": {
                "type": "accountAttribute",
                "attributes": {
                  "sourceName": "Base",
                  "attributeName": "ULTIMO_SOBRENOME"
                }
              }
            }
          },
          "terc": {
            "type": "static",
            "attributes": {
              "value": "terceiro-"
            }
          }
        }
      },
      "type": "usernameGenerator"
    },
    {
      "name": "email",
      "transform": {
        "type": "identityAttribute",
        "attributes": {
          "name": "email"
        }
      },
      "attributes": {},
      "isRequired": false,
      "type": "string",
      "isMultiValued": false
    },
    {
      "name": "displayName",
      "transform": {
        "type": "identityAttribute",
        "attributes": {
          "name": "displayName"
        }
      },
      "attributes": {},
      "isRequired": false,
      "type": "string",
      "isMultiValued": false
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![reinajss](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/reinajss/32/12652_2.png) [@reinajss](https://developer.sailpoint.com/discuss/u/reinajss)\
**Post date:** [March 28, 2023, 5:37pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753/3 "2023-03-28T17:37:01Z")

</div>

> [@tyler\_mairose](#):
>
> The transform looks valid.
> 
> The `usernameGenerator` transform is meant to be used during account creation, so it would be attached to an account create provisioning policy.

Thank you for your help, I create this policy, but I have a question. Every time a new identity is created in this profile will this policy run and the email will be calculated and created without the risk of duplicated it?

---

<div class="post-metadata">

**Author:** ![tyler\_mairose](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tyler_mairose/32/30112_2.png) [@tyler\_mairose](https://developer.sailpoint.com/discuss/u/tyler_mairose)\
**Post date:** [March 28, 2023, 6:08pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753/4 "2023-03-28T18:08:30Z")

</div>

Yes, when a new Identity is created this will run and will create a unique username under the attribute `criaEmailTerceiro`.

The usernameGenerator will traverse through your patterns list until it has a unique username that is not being used.

---

<div class="post-metadata">

**Author:** ![reinajss](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/reinajss/32/12652_2.png) [@reinajss](https://developer.sailpoint.com/discuss/u/reinajss)\
**Post date:** [March 28, 2023, 11:09pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753/5 "2023-03-28T23:09:07Z")

</div>

Hi Tyler,

I was reading about this transformation process, and I noticed that referring to usernameGenerator on the website it says: **“The generator only checks the accountID.”** And so I won’t be able to use this process.  
I wanted to know if it is possible to create this validation process in another way, that is, create a validation if the email already exists in the IDNow base, and if it exists, use the other way as we did here:" “ **$terc$f1$ln@ domain.com.br** ”,  
“ **$terc$f2$ln@dominio.com.br** ”,  
“ **$terc$f1$f3$ln@dominio.com.br** ”,  
“ **$terc$f2$f3$ln@dominio.com.br** ”,  
“ **$terc$f1.$ln{uniqueCounter}@dominio.com.br** ”", is it possible to do this without using usernameGenerator?

I am very grateful for your help.

---

<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:24pm UTC](https://developer.sailpoint.com/discuss/t/usernamegenarator/9753/6 "2023-07-19T14:24:40Z")

</div>


