Hi Folks,
I am trying now to generate a new attribute out of an old one.
I want the attribute vm.name which is "Test_Archive" in a new attribute vm_new.name "Clone_Test_Archive". I tried the following code:
new_vm_name.name = "Clone_"+vm.name
I get an error: TypeError: Cannot set property "name" of null to "Clone_Test_Archive"
Where is my error?
Thanks a lot.
Chris
To see if the VM already exists, you have to check every existing VM if the name is the one you are searching for. Here a sample:
var vmExists = false;
if ( new_vm_name == "" ) throw "no VM name to search for";
var myVirtualMachines = VcPlugin.getAllVirtualMachines();
for each (var myVirtualMachine in myVirtualMachines)
{
if ( new_vm_name == myVirtualMachine.name )
vmExists = true;
}
if ( vmExists == true )
{
System.log( "VM with name " + new_vm_name + " exists." );
}
Regards,
Chris
Hi Chris,
in your code the object "new_vm_name" is not a VcVirtualMachine object, so it does not have a .name attribute. You could correct this by setting: new_vm_name = "Clone_"+vm.name which results in an String object named "new_vm_name" with the value you requested. Or you define "new_vm_name" as VcVirtualMachine object before setting the name value of it by defining the object: var new_vm_name = new VcVirtualMachine(); But I think the first option is the one you need 😉
Regards,
Chris
Hi Chris,
copying the value in a string works fine. But I need a decision weather a VM with the name "Clone_"+vm.name already exists. As far I can see this is not possible with a strin value. Right?
Regards
Chris
I am adding a picture. perhaps this helps, to understand, what I want to do.
Thanks in advance.
Chris
To see if the VM already exists, you have to check every existing VM if the name is the one you are searching for. Here a sample:
var vmExists = false;
if ( new_vm_name == "" ) throw "no VM name to search for";
var myVirtualMachines = VcPlugin.getAllVirtualMachines();
for each (var myVirtualMachine in myVirtualMachines)
{
if ( new_vm_name == myVirtualMachine.name )
vmExists = true;
}
if ( vmExists == true )
{
System.log( "VM with name " + new_vm_name + " exists." );
}
Regards,
Chris