Samaccount Name & unique counter

Hi,
Our client wants all users to have 3 random digits in their username.
What I’ve used is a 2 digit randomly generated followed by a unique counter up to 9. However this doesn’t give 3 digits if the random 2 are unique.
I’ve tried doing some velocity scripting to manipulate the output to add a ‘0’ if there are only 2 numbers, but its not liking it.

        {
            "name": "sAMAccountName",
            "transform": {
                "type": "static",
                "attributes": {
                    "value": "#set($numbers = $input.replaceAll(\"[^0-9]\", \"\"))#if($numbers.length() == 2)#set($input = \"$input0\")#end$input",
                    "input": {
                        "type": "rule",
                        "attributes": {
                            "name": "Create Unique LDAP Attribute"
                        }
                    },
                    "attributes": {
                        "template": "$(samaccountnameCalculate)$(uniqueCounter)",
                        "cloudMaxUniqueChecks": "9",
                        "cloudMaxSize": "20",
                        "cloudRequired": "true"
                    }
                }
            },
            "attributes": {},
            "isRequired": true,
            "type": "string",
            "isMultiValued": false
        }

Any suggestions would be fantastic.
Thanks

Hey @phil_awlings!

I’m guessing that $input0 doesn’t work because the 0 is being interpreted as part of the variable name. You can try ${input}0 instead to get around that.

The syntax also appears to be off within your static transform - there shouldn’t be an attributes property in there directly. Should that go somewhere else? You should have your value in there, along with any variables you’re going to be using within the value (like $input).

Hi,

The create ldap unique attributes works only for account id not for account name. If you want to check uniqueness for account name then we should write a attribute generator rule.

-Abhinov

1 Like

Hi @sup3rmark ,
Thanks for the spot with the ‘0’, but unfortunately that didn’t resolve the issue. I get what you are saying about the syntax, it feels and looks wrong, but I just wrapped the original code in the ‘input’ variable. I have a suspicion that what I’m trying to do isn’t feasible. I might just have to use a random 3 digit generator instead. The chances of the number replicating is very low, even considering we’ve got 500k users.

@Abhinov7 LDAP works fine for account name, this is the original code:

        {
            "name": "sAMAccountName",
            "transform": {
                "type": "rule",
                "attributes": {
                    "name": "Create Unique LDAP Attribute"
                }
            },
            "attributes": {
                "template": "$(samaccountnameCalculate)$(uniqueCounter)",
                "cloudMaxUniqueChecks": "10",
                "cloudMaxSize": "20",
                "cloudRequired": "true"
            },
            "isRequired": true,
            "type": "string",
            "isMultiValued": false
        }
1 Like

@phil_awlings for such customization we would recommend to go and write a cloud account attribute generator rule as mentioned in the below link.

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