Orchestrator Workflow Action to Create or Update a Custom Attribute

by Simon Sparks · February 15, 2016

vCO Workflow Script to Create or Update a Custom Attribute

var objVcSdkConnection = objVcVirtualMachine.vimHost;
	
var objVcCustomFieldsManager = objVcSdkConnection.customFieldsManager;

var arrVcCustomFieldDef = objVcCustomFieldsManager.field;

var strKey = "";

for (var i = 0; i < arrVcCustomFieldDef.length; i++)
{
	var objVcCustomFieldDef = arrVcCustomFieldDef[i];

	if (objVcCustomFieldDef.name == strCustomFieldName)
	{
		strKey = objVcCustomFieldDef.key;
		
		break;
	}
}

if ( strKey == "" )
{
	var objVcCustomFieldDef = objVcCustomFieldsManager.addCustomFieldDef(strCustomFieldName);
	
	strKey = 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