Orchestrator Workflow Action to Create or Update a Custom Attribute

by Simon Sparks · 15 February 2016

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

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

Filename: vCenterService.ts

Function VcVirtualMachineCustomAttributeCreateOrUpdate

Description: Orchestrator Workflow Function to Create or Update a Custom Attribute

publicVcVirtualMachineCustomAttributeCreateOrUpdate(objVcVirtualMachine:VcVirtualMachine,strVcCustomFieldName:string):string{
letobjVcSdkConnection:VcSdkConnection=objVcVirtualMachine.vimHost;

letobjVcCustomFieldsManager:VcCustomFieldsManager=objVcSdkConnection.customFieldsManager;

letarrVcCustomFieldDef:VcCustomFieldDef[]=objVcCustomFieldsManager.field;

letobjVcCustomFieldDef:VcCustomFieldDef;

objVcCustomFieldDef=arrVcCustomFieldDef.find((objVcCustomFieldDef:VcCustomFieldDef)=>{
returnobjVcCustomFieldDef.name==strVcCustomFieldName;
});

if (objVcCustomFieldDef===undefined )
{
objVcCustomFieldDef=objVcCustomFieldsManager.addCustomFieldDef(strVcCustomFieldName);
}

letstrKey:string=objVcCustomFieldDef.key;

objVcCustomFieldsManager.setField(objVcVirtualMachine,strKey,strNewCustomFieldValue);
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like