vCO Workflow Script to Get the Current Value of a Custom Attribute

vCO Workflow Script to Get the Current Value of a Custom Attribute

 

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

var arrVcCustomFieldDef;
	arrVcCustomFieldDef = objVcCustomFieldsManager.field;

var strReturnValue;
	strReturnValue = "";

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

	var strKey = objVcCustomFieldDef.key;
	var strName = objVcCustomFieldDef.name;

	if (strName == strCustomFieldName)
	{
		var arrCustomFieldValue;
			arrCustomFieldValue = objVcVirtualMachine.customValue;
		
		for (var x = 0; x < arrCustomFieldValue.length; x++)
		{
			var objCustomFieldValue;
				objCustomFieldValue = arrCustomFieldValue[x];
		
			if (objCustomFieldValue.key == strKey)
			{
				strReturnValue = objCustomFieldValue.value;
				
				break;
			}
		}
	}
}

return strReturnValue;

Leave a Reply