VMware Cloud Community
JorgeRodriguez2
Contributor
Contributor

Keep getting error when "TypeError: Cannot read property "virtualMachineID" from null (Dynamic Script Module name : getPropertiesFromVirtualMachine"

I keep getting the error below when i run my workflow :

[2019-06-23 12:29:13.783] [I] 1 match uuid: 50320c66-3431-ed1d-68ad-f96256cf4290

[2019-06-23 12:29:13.786] [I] Resolved vCAC VM: vROps-ap1

[2019-06-23 12:29:13.841] [E] Workflow execution stack:

***

item: 'Get Info/Shutdown (UC1)/item3', state: 'failed', business state: 'null', exception: 'TypeError: Cannot read property "virtualMachineID" from null (Dynamic Script Module name : getPropertiesFromVirtualMachine#1)'

workflow: 'Get Info/Shutdown (UC1)' (fd7316ef-7b9b-483a-b5df-5d5d07e45c1b)

|  'attribute': name=VMName type=string value=

|  'attribute': name=VMAddress type=string value=

|  'attribute': name=VMOwner type=string value=

|  'attribute': name=VMBsgroup type=string value=

|  'attribute': name=VMReservation type=string value=

|  'attribute': name=actionResult type=vCAC:VirtualMachine value=__NULL__

|  'attribute': name=vCACIaaSHost type=vCAC:VCACHost value=__NULL__

|  'attribute': name=errorCode type=string value=TypeError: Cannot read property "virtualMachineID" from null (Dynamic Script Module name : getPropertiesFromVirtualMachine#1)

|  'input': name=vCenterVm type=VC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='10.20.20.50%2Cid:vm-32'&dunesName='VC:VirtualMachine'

|  'output': name=actionResult1 type=vCAC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='31b63e72-1b20-4cc6-a61b-5af4db5f8ee3/ba9a8a14-17ae-45f4-abbe-dca45f3fc0d0'&dunesName='vCAC:VirtualMachine'

*** End of execution stack.

Flow chart is as below:

pastedImage_0.png

pastedImage_1.png

Code from QCgetvCACVmFromvC action:

//Auto generated script, cannot be modified !

actionResult = System.getModule("org.company.mymodule").QCgetvCACVmFromvCenterVmUuid(vCenterVm) ;

Code from show info:

//Gets the IP Address Of the VM

vCACVmExtendedProps = System.getModule("com.vmware.library.vcac").getPropertiesFromVirtualMachine(vCACIaaSHost,vCACVM);

VMAddress = vCACVmExtendedProps.get("__datacollected_ipaddress");

//Gets the name of VM

VMHostname = vCACVM.vmDNSName;

//Gets the owner of VM

VMOwner = vCACCAFEFilterParam.substringOf("owners/ref",vCACCAFEFilterParam.string("user@domain.com"));

//Gets the Business Group of the VM

var VMBsgroup = System.getContext().getParameter("_asd_subTenantref")

//Gets the Reservation of the VM

var id = virtualMachine.getEntity().getProperty("HostReservationID");

var entity;

var idprop = new Properties( {

"HostReservationID" : id

});

if (!id || id == "") throw "Error getting Reservation ID of VM.";

if (host != null) {

entity = vCACEntityManager.readModelEntity(host.id, "ManagementModelEntities.svc", "HostReservations", idprop, null);

} else {

var hosts = Server.findAllForType("vCAC:VCACHost");

System.debug("hosts: " + hosts);

for each (var host in hosts) {

try {

entity = vCACEntityManager.readModelEntity(host.id, "ManagementModelEntities.svc", "HostReservations", idprop, null);

} catch (e) {

throw "Error reading model entity.";

}

}

}

VMReservation = entity.getInventoryObject();

//Return Values

Server.log("Hostname : " + VMHostname);

Server.log("IP Address : " + VMAddress);

Server.log("Owner : " + VMOwner);

System.log("Business Group name: " + VMBsgroup);

System.log("Reservation of VM: " + VMReservation);

I'm not sure what the issue might be?

Reply
0 Kudos
5 Replies
qc4vmware
Virtuoso
Virtuoso

I'd need you to upload your workflow to debug it... I can't tell really from what you've shown so far.  Obviously something is null but it looks like things are mapped correctly.

Reply
0 Kudos
JorgeRodriguez2
Contributor
Contributor

Attached is the workflow,

pastedImage_0.png

I managed to get it to run without any errors but i'm getting alot of null values.

I need to print out the VM Host name, The Business Group it belongs to, and the Reservation its part of, the Owner of VM.

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

Its a bit confusing looking through this workflow.  I'm assuming this is being called during an event subscription or as part of an XaaS catalog item or action?  Some of the code you are trying to run will only work under that context.

In the first snippet you need to set an out put for vCACVM so that it gets carried throughout the rest of the workflow.  You also need to set it to the first item in the array.  Change the line:

var vCACVM = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + Uuid + "'");

With this line

var vCACVM = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + Uuid + "'")[0];

Server.findAllForType returns an array.  The array should only have one item in it so take the first item.

Paul

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

Here is an action that will retrieve the vm's reservation.

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

You can get the business group by looking up based on the vCACVM subtenantId.  It is a property of the vm.  I think you might have better luck looking at the catalog resource though.  There is tons of information in the resource data, there is an owners property as well.  I've attached an action that will retrieve the catalog resource for a vCACVm.  Hope all of this helps.

Reply
0 Kudos