Hello,
I spend a lot of time already trying to find out how can I put VM which I found into moveIntoFolder_Task.
What I'm trying to do:
1. create a folder
2. find a VM provided into text field
3. Move this VM into target folder.
try {newFolder = parentFolder.createFolder("test1");}
catch(err){}
findVM(vmname);
function findVM(vmname) {
allVms = System.getModule("com.vmware.library.vc.folder").getAllVirtualMachinesByFolder(parentFolder);
ret = null; for (var i in allVms) {
if (allVms[i].name == vmname) { ret = allVms[i]; break; } } return ret;
}
var vms1 = new Array();
//vms1 = [];
vms1 = vms1.push(ret);
task = newFolder.moveIntoFolder_Task(vms1);
var actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,progress,pollRate) ;
vms1 is it VC:VirtualMachine type- however when I select this variable manually as an attribute - this works fine, I can cmove VM into target folder.
When I'm finding this VM by using findVM{} function I'm getting following error:
state: 'failed', business state: 'null', exception: 'Cannot convert 1.0 to com.vmware.vmo.plugin.vi4.model.VimManagedEntity[]
Do you know how can I convert VM into VimManagedEntity data type?
Hi,
You don't need to convert VM to VimManagedEntity.
The problem is the following part of your code:
vms1 = vms1.push(ret);
task = newFolder.moveIntoFolder_Task(vms1);
It seems you expect the first line to push the ret object to vms1 array and return the array object itself, which then you pass as an argument to moveIntoFolder_Task() method.
The problem is that the push() method returns not the array object but the length of the array. So you are actually calling moveIntoFolder_Task() method with argument of type number instead of with argument of type array of VMs, and that's why you get this 'Cannot convert ...' exception
So the solution is to replace:
vms1 = vms1.push(ret);
with just (no assignment)
vms1.push(ret);
Hi,
You don't need to convert VM to VimManagedEntity.
The problem is the following part of your code:
vms1 = vms1.push(ret);
task = newFolder.moveIntoFolder_Task(vms1);
It seems you expect the first line to push the ret object to vms1 array and return the array object itself, which then you pass as an argument to moveIntoFolder_Task() method.
The problem is that the push() method returns not the array object but the length of the array. So you are actually calling moveIntoFolder_Task() method with argument of type number instead of with argument of type array of VMs, and that's why you get this 'Cannot convert ...' exception
So the solution is to replace:
vms1 = vms1.push(ret);
with just (no assignment)
vms1.push(ret);
Yep- this work.
Thank you for your help.