Custom Forms = Custom Naming?


UPDATE:

So the code I used has a bit of a bug. When going from 1 digit length up to 2 it adds the 0 to it still. I believe its based off the default “inum” in the code. I’ve updated the code below. Notice, I went a different route, so that I can run if/else clauses per length as needed(depending on how many digits you want to go). I’m ok with just 2, so I’m running the following:
if(type == null)
{
return ""
}
else{
name = app + "-" + env + "-" + type
var inum = ""
sSearchPattern = name + inum
// Get a list of computers matching the pattern in strComputer
var computers = ActiveDirectory.getComputerADRecursively(sSearchPattern,defaultADServer);
if(computers[0] != null)
{
for each (computer in computers)
{
inum = Math.max(inum, computer.name.substring(sSearchPattern.length));
}
}
inum=inum+1;
var snum=String(inum)
if(snum.length == "1") {snum = "0" + snum;}
else{
//donothing
}
//build the new name
var newName = sSearchPattern+snum
// Validate the newly minted name, to make sure it doesn't exist
var computers = ActiveDirectory.getComputerADRecursively(newName,defaultADServer);
if(computers[0] == null)
{
newComputerName = newName;
}
else
{}
return newName;
}

Original blog below:

So, the white whale for me in automation has been custom naming. VRA allows for specific naming with some numerical iteration, but that’s not always fit the bill. Besides, why can’t I use the naming convention as a dynamic field within custom forms? IS ANYONE READING THIS?

wcft

Anyway. There are SO MANY WAYS to do this, it seems silly to add another, but, since I learned from so many people out there, I figured giving back may help someone else.

So your going to first create an action in vRO. Once you login set the dropdown to “Design” – Right-Click on the folder you want to create the action and click “Add action…”

customnaming4

THE CODE!


name = location + "-" + domain + "-" + app
var inum = 0
sSearchPattern = name + inum
// Get a list of computers matching the pattern in strComputer
var computers = ActiveDirectory.getComputerADRecursively(sSearchPattern,defaultADServer);
if(computers[0] != null)
{
foreach(computer in computers)
{
inum = Math.max(inum, computer.name.substring(sSearchPattern.length));
}
}
inum=inum+1;
var snum=String(inum)
while (snum.length < (2)) {snum = "0" + snum;}
var newName = sSearchPattern+snum
var computers = ActiveDirectory.getComputerADRecursively(newName,defaultADServer);
if(computers[0] == null)
{
newComputerName = newName;
}
else
{}
return newName;

NOTE!! It is assumed each input will be static and have a set default (i.e. Never null). So make sure each input has a default setting…

Basic theory here is that our naming convention is AA-BBB-CCC001(you can change this to anything, it’s not really the crux of this). But what your looking for is the “Math.max”; it’s just delightful. The inputs I used are as follows:

customnaming3

1. location–string
2. domain–string
3. app–string
4. defaultADServer–AD:AdHost

With this as an action, you can do some awesome stuff with custom forms.
For instance, you can set a deployment per app, or environment, create those inputs as static, and type as a dynamic dropdown.
Pretty simple.

    1. Create the Action with the code above and the inputs, and give it a pretty cool name(like edgar)
    2. Create Custom Properties for each input needed BUT the Ad:host (we’ll discuss that later.)
    3. Use custom forms! Activate it, and get a beer… you deserve it, you smart person you.
    4. Bring each input over that you need to use (if the are static only bring over the ones needed for dynamic).
    5. customnaming1For “Hostname”, use external source, and under action, type in the name of your action: (edgar)
    6. For the inputs select “FIELD”, then select the proper custom  property input you created. Then for “defaultADServer” use “Constant”. This will pull the AD Endpoints you have created. Point it to the AD you intend to use (if you want this dynamic you can use it as a field dropdown).
    7. For whatever you wish to create dynamic, set the field to a dropdown, and set the values to “Value|Label,Value|Label”.

Now the external Action will populate the Hostname, and wonderful custom naming “should” be yours.

customnaming2

Good job, get beer.


%d bloggers like this: