Function: Get the Current Value of 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 Script to Get the Current Value of a Custom Property in vRealize Automation v7.x

public CustomPropertyGetValue(objVcVirtualMachine: VcVirtualMachine, strPropertyNameToFind:string): string {

    let objVcVirtualMachineConfigInfo: VcVirtualMachineConfigInfo = objVcVirtualMachine.config;

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

    let objvCACVirtualMachine: vCACVirtualMachine = arrvCACVirtualMachine[0];

    let objvCACEntity: VCACEntity = objvCACVirtualMachine.getEntity();

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

    let arrVCACEntityProperties: VCACEntity[] = objvCACEntity.getLink(objvCACHost, "VirtualMachineProperties");

    var strReturnValue: string = "";

    for (var i = 0; i < arrVCACEntityProperties.length; i++) {
        var objVCACEntityProperties: VCACEntity = arrVCACEntityProperties[i];

        var strPropertyName: string = objVCACEntityProperties.getProperty("PropertyName");

        var strPropertyValue: string = objVCACEntityProperties.getProperty("PropertyValue");

        if (strPropertyName == strPropertyNameToFind) {
            strReturnValue = strPropertyValue;

            break;
        }
    }

    return strReturnValue;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like