vCO Workflow Script to Find a vCloud vApp Template object by Name

The following script enables you to find a vCloud vApp Template object by name

 

 

var objVclExpressionTEMPLATE;
	objVclExpressionTEMPLATE = new VclExpression(VclQueryVAppTemplateField.NAME, strDeployDataCentre + "-CurrentTemplates*", VclExpressionType.EQUALS);

var objVclExpressionCATALOG;
	objVclExpressionCATALOG = new VclExpression(VclQueryVAppTemplateField.CATALOGNAME, "Global Master", VclExpressionType.EQUALS);

var objVclExpressionVDC;
	objVclExpressionVDC = new VclExpression(VclQueryVAppTemplateField.VDCNAME, "Catalogs*", VclExpressionType.EQUALS);

var arrVclExpression;
	arrVclExpression = new Array();
	arrVclExpression.push(objVclExpressionTEMPLATE);
	arrVclExpression.push(objVclExpressionCATALOG);
	arrVclExpression.push(objVclExpressionVDC);

var objVclFilter;
	objVclFilter = new VclFilter(arrVclExpression, VclFilterType.AND);

var arrFields;
	arrFields = new Array();
	arrFields.push(VclQueryVAppTemplateField.NAME);

var objVclQueryParams;
	objVclQueryParams = new VclQueryParams();
	objVclQueryParams.setFilter(objVclFilter);
	objVclQueryParams.setFields(arrFields);

var objVclQueryService;
	objVclQueryService = objVclHost.getQueryService();

var objVclAbstractRecordResultSet;
	objVclAbstractRecordResultSet = objVclQueryService.queryRecords(VclQueryRecordType.VAPPTEMPLATE, objVclQueryParams);

if (objVclAbstractRecordResultSet == null) 
{
	throw "No matching catalogue items found.";
}
else
{
	var arrVclQueryResultVAppTemplateRecord;
		arrVclQueryResultVAppTemplateRecord = objVclAbstractRecordResultSet.getRecords(new VclQueryResultVAppTemplateRecord());

	for each (var objVclQueryResultVAppTemplateRecord in arrVclQueryResultVAppTemplateRecord) 
	{
		var objVclReference;
			objVclReference = new VclReference();
			objVclReference.href = objVclQueryResultVAppTemplateRecord.href;
			objVclReference.name = objVclQueryResultVAppTemplateRecord.name;

		if ( objVclQueryResultVAppTemplateRecord.name == "CurrentTemplates" )
		{
			var objVclVAppTemplate;
				objVclVAppTemplate = objVclHost.getEntityByReference(VclFinderType.VAPP_TEMPLATE, objVclReference);
		}
	}

	if ( objVclVAppTemplate == null )
	{
		throw "The vApp Templates were NOT found.";
	}
}

Leave a Reply