vCO Workflow Script to Create or Update a Custom Attribute

vCO Workflow Script to Create or Update a Custom Attribute

 

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

var arrVcCustomFieldDef;
	arrVcCustomFieldDef = objVcCustomFieldsManager.field;

var strKey;
	strKey = "";

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

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

if ( strKey == "" )
{
	var objVcCustomFieldDef;
		objVcCustomFieldDef = objVcCustomFieldsManager.addCustomFieldDef(strCustomFieldName);
	
	strKey = objVcCustomFieldDef.key;
}

objVcCustomFieldsManager.setField(objVcVirtualMachine, strKey, strNewCustomFieldValue);

Leave a Reply