You can cut, paste, and edit the JavaScript examples to write scripts for CRUD vRealize Automation tasks.

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

Create a vRealize Automation Model Entity

This example script performs the following actions:

  1. Defines the model name and the entity set name.

  2. Defines the properties of the host prefix.

  3. Saves the host prefix entity.

  4. Defines the properties of the provisioning group.

  5. Defines the provisioning group as a link.

  6. Saves the provisioning group entity, by linking it with the host name prefix.

Table 1. Input Variables

Variable

Type

host

vCAC:VcacHost

var modelName = 'ManagementModelEntities.svc';
var entitySetName = 'HostNamePrefixes';
var links = null;
var headers = null;
//Create properties for prefix entity
var prefixInputProperties = {
   MachinePrefix:'test-prefix',
   NextMachineNo:1,
   MachineNumberLength:3
};
//Save the prefix
var prefixEntity = vCACEntityManager
  .createModelEntity(host.id, modelName, entitySetName, prefixInputProperties, links, headers);
entitySetName = 'ProvisioningGroups';
//Create properties for the provisioning group entity
inputProperties = {
   GroupName:'TestGroupName',
   GroupDescription:'This group was generated with a vCO workflow',
   AdministratorEmail:'test@test.com',
   AdContainer:'AD',
   IsTestGroup:false,
   Flags:2,
   GroupType:1};
//Add a reference to the newly created prefix entity
links = {
 HostNamePrefix:prefixEntity
};
//Save the provisioning group
var entity = vCACEntityManager.createModelEntity(host.id, modelName, entitySetName, inputProperties, links, headers);

Update a vRealize Automation Model Entity

This example script performs the following actions:

  1. Gets the host ID from the provided entity.

  2. Gets the model name from the provided entity.

  3. Gets the entity set name from the provided entity.

  4. Gets the entity ID from the provided entity.

  5. Defines a set of properties that will be updated.

  6. Starts the action responsible for updating the entity.

Table 2. Input Variables

Variable

Type

entity

vCAC:Entity

updatedDescription

String

var hostId = entity.hostId;
var modelName = entity.modelName;
var entitySetName = entity.entitySetName;
var entityIdString = entity.keyString;
var links = null;
var headers = null;
var updateProperties = new Properties();
updateProperties.put("UserNameDescription", updatedDescription);
//Update the user description
System.getModule("com.vmware.library.vcac")
  .updateVCACEntity(hostId, modelName, entitySetName, entityIdString, updateProperties, links, headers);

Read a vRealize Automation Model Entity

This example script performs the following actions:

  1. Defines the model name and the entity set name.

  2. Defines the blueprint ID with a property object.

  3. Reads the entity.

Table 3. Input Variables

Variable

Type

host

vCAC:VcacHost

blueprintID

String

var modelName = 'ManagementModelEntities.svc';
var entitySetName = 'VirtualMachineTemplates';
var links = null;
var headers = null;
//Create properties for the prefix entity
var blueprintId = {
  VirtualMachineTemplateID:blueprintId,
};
//Read the blueprint
var entity = vCACEntityManager
  .readModelEntity(host.id, modelName, entitySetName, blueprintId, headers);

Delete a vRealize Automation Model Entity

This example script performs the following actions:

  1. Gets the host ID from the provided entity.

  2. Gets the model name from the provided entity.

  3. Gets the entity set name from the provided entity.

  4. Gets the entity ID from the provided entity.

  5. Starts the action responsible for deleting the entity.

Table 4. Input Variables

Variable

Type

entity

vCAC:Entity

var hostId = entity.hostId;
var modelName = entity.modelName;
var entitySetName = entity.entitySetName;
var entityKeyString = entity.keyString;
var headers = null;
//Delete the entity
System.getModule("com.vmware.library.vcac")
  .deleteVCACEntity(hostId, modelName, entitySetName, entityKeyString, headers);

Read a vRealize Automation Entity by Custom Filter

This example script performs the following actions:

  1. Defines the model name and the entity set name.

  2. Defines the properties by which the entities are filtered.

  3. Reads a list of entities.

Table 5. Input Variables

Variable

Type

host

vCAC:VcacHost

templateName

String

var modelName = 'ManagementModelEntities.svc';
var entitySetName = 'VirtualMachineTemplates';
var headers = null;
//Create properties for prefix entity
var properties = {
   VirtualMachineTemplateName:templateName,
};
//Read a list of entities
var entities = vCACEntityManager
  .readModelEntitiesByCustomFilter(host.id, modelName, entitySetName, properties, headers);

Read a vRealize Automation Entity by System Query

This example script performs the following actions:

  1. Defines the model name and the entity set name.

  2. Defines the system queries by which the entities are filtered and selects the top ten results of all virtual machines, filtered by the machine state and component flag.

  3. Reads a list of entities.

Table 6. Input Variables

Variable

Type

host

vCAC:VcacHost

var modelName = 'ManagementModelEntities.svc';
var entitySetName = 'VirtualMachines';
var filter = "VirtualMachineState eq 'Off' and IsComponent eq true";
var orderBy = 'VirtualMachineName asc';
var top = 10; {
var skip = 0;,
var headers = null;
var select = null;
var entities = vCACEntityManager
  readModelEntitiesBySystemQuery(host.id, modelName, entitySetName, filter, orderBy, select, top, skip, headers);