vCO Workflow Script to Create or Update a Custom Property
var arrvCACVirtualMachine; arrvCACVirtualMachine = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + objVcVirtualMachine.config.instanceUuid + "'"); var objvCACVirtualMachine; objvCACVirtualMachine = arrvCACVirtualMachine[0]; var objvCACEntity; objvCACEntity = objvCACVirtualMachine.getEntity(); var objvCACHost; objvCACHost = Server.findForType("vCAC:VCACHost", objvCACEntity.hostId); var blnFound; blnFound = false; var objProperties; objProperties = new Properties(); objProperties.put("PropertyName", strPropertyName); objProperties.put("PropertyValue", strPropertyValue); objProperties.put("IsHidden", false); objProperties.put("IsRuntime", false); objProperties.put("IsEncrypted", false); var objPropertiesLinks; objPropertiesLinks = new Properties(); objPropertiesLinks.put("VirtualMachine", objvCACEntity); var arrvCACEntityVirtualMachineProperties; arrvCACEntityVirtualMachineProperties = objvCACEntity.getLink(objvCACHost, "VirtualMachineProperties"); for ( var i = 0; i < arrvCACEntityVirtualMachineProperties.length; i++ ) { var objvCACEntityVirtualMachineProperties; objvCACEntityVirtualMachineProperties = arrvCACEntityVirtualMachineProperties[i]; var strPropertyNameLoop; strPropertyNameLoop = objvCACEntityVirtualMachineProperties.getProperty("PropertyName"); if (strPropertyNameLoop == strPropertyName) { blnFound = true; break; } } if (blnFound == true) { var objEntityKey; objEntityKey = objvCACEntityVirtualMachineProperties.entityKey; var strEntityKeyId; strEntityKeyId = objEntityKey.get("Id"); vCACEntityManager.updateModelEntityBySerializedKey(objvCACHost.id, "ManagementModelEntities.svc", "VirtualMachineProperties", strEntityKeyId, objProperties, objPropertiesLinks); } else { vCACEntityManager.createModelEntity(objvCACHost.id, "ManagementModelEntities.svc", "VirtualMachineProperties", objProperties, objPropertiesLinks); }