You can cut, paste, and edit the JavaScript examples to write scripts for finding vCloud Automation Center entities by using the vCACCAFEEntitiesFinder scripting utility object.

For more information about scripting in vCenter Orchestrator, see Developing with VMware vCenter Orchestrator.

Find Catalog Resources Filtered by Name

Table 1. Input Variables

Variable

Type

host

vCAC:VcacHost

You can use one the following examples:

  • This example script gets all catalog resources for the target host matching the query of name_of_the_resource by name and description.

    var items = vCACCAFEEntitiesFinder.findCatalogResources(host, "name_of_the_resource");
  • This example script performs the following actions:

    1. Gets the Consumer Resource service and invokes the get method passing as a Pageable parameter an instance of the vCACCAFEPageOdataRequest object.

    2. Creates the vCACCAFEPageOdataRequest object by providing an OData query as a single filter of the name attribute matching the name_of_the_resource string.

    var service = host.createCatalogClient().getCatalogConsumerResourceService(); 
    
    var filter = new Array();
    filter[0] = vCACCAFEFilterParam.equal("name", vCACCAFEFilterParam.string("name_of_the_resource"));
    var query = vCACCAFEOdataQuery.query().addFilter(filter); 
    
    var items = service.getResourcesList(new vCACCAFEPageOdataRequest(query));

Find Catalog Resources Filtered by Owner

This example script performs the following actions:

  1. Gets the Consumer Resource service and invokes the get method passing as a Pageable parameter an instance of the vCACCAFEPageOdataRequest object.

  2. Creates the vCACCAFEPageOdataRequest object by providing an OData query as a single filter of the owner/ref attribute matching the user@domain.com string.

    The owners/ref attribute is a composition based on the internal structure and fields of the catalog resources. The vCACCAFECatalogResource entity has the owners attribute, which is a collection of vCACCAFECatalogPrincipal entities. The vCACCAFECatalogPrincipal entity has the ref property, which is a string representation of the principal id of the user.

var filter = new Array();
filter[0] = vCACCAFEFilterParam.substringOf("owners/ref", vCACCAFEFilterParam.string("user@domain.com"));
var query = vCACCAFEOdataQuery.query().addFilter(filter);

var items = service.getResourcesList(new vCACCAFEPageOdataRequest(query));

Find Catalog Resources Filtered by Name and Owner

This example script combines the OData queries from the previous two examples into a single one condition by using the vCACCAFEFilterParam.and(array of conditions) logic operator.

var conditions = new Array();
conditions[0] = vCACCAFEFilterParam.equal("name", vCACCAFEFilterParam.string("name_of_the_resource_here"));
conditions[1] = vCACCAFEFilterParam.substringOf("owners/ref", vCACCAFEFilterParam.string("user@domain.com"));

var filter = new Array();
filter[0] = vCACCAFEFilterParam.and(conditions);
var query = vCACCAFEOdataQuery.query().addFilter(filter);

var items = service.getResourcesList(new vCACCAFEPageOdataRequest(query));

You can define other conditions by using different logic operators such as vCACCAFEFilterParam.group(array of parameters), vCACCAFEFilterParam.not(parameter), vCACCAFEFilterParam.startsWith(id, string), vCACCAFEFilterParam.endsWith(id, string), vCACCAFEFilterParam.greaterThan(id, number), vCACCAFEFilterParam.lessThan(id, number), and so on.