esstokes1
Enthusiast
Enthusiast

Query VDC from vCO

Jump to solution

I'm attaching the package that I'm attempting to execute.  I have an action that searches for a OrgvDC based on a string and returns an array of type vCloud:vdc.  I'm calling this action from the workflow and attempting to write out the name and status of the OrgvDC but it's not working.  The error is "TypeError: Cannot read property "name" from null (Workflow:CheckGetVDCByName / Check VDC (item2)#2)".  According to what I'm writing out to System.log there is at least 1 item returned from the action.  I cannot figure out what's going on with the workflow script and why it doesn't see the OrgVDC as a valid object.  Any suggestions?

Thanks

1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee

Try using the following code inside your action (Just delete your current content and replace with this):

var queryService = vcdHost.getQueryService();
var expression = new VclExpression(VclQueryOrgVdcField.NAME, name, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);

var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINORGVDC, params);

var vdcs = new Array();

while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultAdminVdcRecord());
    System.log(records.length + " records found");
    for each (record in records) {
        var vdcRef = new VclReference();
        vdcRef.href = record.href;
        vdcRef.name = record.name;
        vdcRef.type = record.type;
        var adminVdc = vcdHost.getEntityByReference(VclFinderType.ADMIN_VDC, vdcRef);
        var vdc = adminVdc.toUserObject();
        //System.log("VDC: "+vdc);
        //System.log("Name: "+record.name+" Type: "+record.type+" HREF: "+record.href);
        vdcs.push(vdc);
    }
    resultSet = resultSet.getNextPage();
}
return vdcs;

Since you are using the "ADMIN" object query/record types, I assume you have your plugin connected to vCD with a SYSTEM level account, so that is how this code was tested...

The resulting records and entity are Admin objects, so note the line "var vdc = adminVdc.toUserObject();" -- I convert the resulting adminVdc object into a regular vCloud:Vdc object, then push the "vdc" variable into the array.

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

Try using the following code inside your action (Just delete your current content and replace with this):

var queryService = vcdHost.getQueryService();
var expression = new VclExpression(VclQueryOrgVdcField.NAME, name, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);

var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINORGVDC, params);

var vdcs = new Array();

while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultAdminVdcRecord());
    System.log(records.length + " records found");
    for each (record in records) {
        var vdcRef = new VclReference();
        vdcRef.href = record.href;
        vdcRef.name = record.name;
        vdcRef.type = record.type;
        var adminVdc = vcdHost.getEntityByReference(VclFinderType.ADMIN_VDC, vdcRef);
        var vdc = adminVdc.toUserObject();
        //System.log("VDC: "+vdc);
        //System.log("Name: "+record.name+" Type: "+record.type+" HREF: "+record.href);
        vdcs.push(vdc);
    }
    resultSet = resultSet.getNextPage();
}
return vdcs;

Since you are using the "ADMIN" object query/record types, I assume you have your plugin connected to vCD with a SYSTEM level account, so that is how this code was tested...

The resulting records and entity are Admin objects, so note the line "var vdc = adminVdc.toUserObject();" -- I convert the resulting adminVdc object into a regular vCloud:Vdc object, then push the "vdc" variable into the array.

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
esstokes1
Enthusiast
Enthusiast

that was it!  thanks!

0 Kudos