VMware Cloud Community
hchchchc
Contributor
Contributor
Jump to solution

Property named 'name' not found on object : VcVirtualMachine

hi,

i'm struggeling with a strange problem.

i try to get all vm's in vcenter(s) via sdk like this:

var sdkConnections = VcPlugin.allSdkConnections;
for (var i = 0; i < sdkConnections.length; i++) {
      var sdkConnection = sdkConnections[i];
      var vms = sdkConnection.getAllVirtualMachines();
      if (vms.length > 0) {
         for (var j = 0; j < vms.length; j++) {
         var vm = vms[j];

after that i try to get the id and name like this (f.e. to write it to the log as an example):

System.log("--->>> DEBUG - ie '" + vm.id + "'");

System.log("--->>> DEBUG - name '" + vm.name + "'");

but several id's DO NOT EXISTS in the vcenter db but come back from the sdk ?!
f.e. there's a vm with id "id-47" which is not in table vpx_vm
but another one with id "id-647" is in that table.
when i try to get the name (vm.name) of both i end up in an exception with the message "Property named 'name' not found on object : VcVirtualMachine".
i already tried to avoid that and check for the existance of the property, but without success.
how can i securely check for the existance of "vm.name" without ending up in an error ?
(other question would be, why do i get vm's through the sdk that don't exist in vcenter ?!)
thanks !!!!!
chris

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Use try/catch...

This will allow your code to continue processing and simply log the errors rather than throwing an exception.

try{

// your code here....

}catch(err){

     System.log("Error: "+err);

}
If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
2 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

Use try/catch...

This will allow your code to continue processing and simply log the errors rather than throwing an exception.

try{

// your code here....

}catch(err){

     System.log("Error: "+err);

}
If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
hchchchc
Contributor
Contributor
Jump to solution

hi burke,

just tried - 3 minutes ago - works perfekt !!

thanks, chris

0 Kudos