Orchestrator Workflow Action to Create or Update a Custom Property

by Simon Sparks · 15 February 2022

To use this function add it to the class library file named vRealizeAutomation.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vRealizeAutomation.ts

Function CustomPropertyGetValue

Description: Orchestrator Workflow Function to Create or Update a Custom Property in vRealize Automation v7.x

public CustomPropertyUpdateValue(objVcVirtualMachine: VcVirtualMachine, strPropertyName: string, strPropertyValue: string): void {

    let objVcVirtualMachineConfigInfo: VcVirtualMachineConfigInfo = objVcVirtualMachine.config;

    let arrvCACVirtualMachine: vCACVirtualMachine[] = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + objVcVirtualMachineConfigInfo.instanceUuid + "'") as vCACVirtualMachine[];

    let objvCACVirtualMachine: vCACVirtualMachine = arrvCACVirtualMachine[0];

    let objVCACEntity: VCACEntity = objvCACVirtualMachine.getEntity();

    let objvCACHost: vCACHost = Server.findForType("vCAC:VCACHost", objVCACEntity.hostId) as vCACHost;

    let blnFound: boolean = false;

    let objProperties: Properties = new Properties();
    objProperties.put("PropertyName", strPropertyName);
    objProperties.put("PropertyValue", strPropertyValue);
    objProperties.put("IsHidden", false);
    objProperties.put("IsRuntime", false);
    objProperties.put("IsEncrypted", false);

    let objPropertiesLinks: Properties = new Properties();
    objPropertiesLinks.put("VirtualMachine", objVCACEntity);

    let objPropertiesHeaders: Properties = new Properties();

    let arrVCACEntityVirtualMachineProperties: VCACEntity[] = objVCACEntity.getLink(objvCACHost, "VirtualMachineProperties");

    for (let i: number = 0; i < arrVCACEntityVirtualMachineProperties.length; i++) {
        let objVCACEntityVirtualMachineProperties: VCACEntity = arrVCACEntityVirtualMachineProperties[i];

        let strPropertyNameLoop: string = objVCACEntityVirtualMachineProperties.getProperty("PropertyName");

        if (strPropertyNameLoop === strPropertyName) {
            blnFound = true;

            let objEntityKey: any = objVCACEntityVirtualMachineProperties.entityKey;

            let strEntityKeyId: string = objEntityKey.get("Id");

            vCACEntityManager.updateModelEntityBySerializedKey(objvCACHost.id, "ManagementModelEntities.svc", "VirtualMachineProperties", strEntityKeyId, objProperties, objPropertiesLinks, objPropertiesHeaders);

            break;
        }
    }

    if (blnFound === false) {
        vCACEntityManager.createModelEntity(objvCACHost.id, "ManagementModelEntities.svc", "VirtualMachineProperties", objProperties, objPropertiesLinks, objPropertiesHeaders);
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like