Friday, March 19, 2010

Retrieve Entity using ConditionExpression,FilterExpression,QueryExpression

ConditionExpression condtionToGetCase = new ConditionExpression();

// Set the ConditionExpressions Properties so that the condition is true when
// the incidentid or the incident/case is equal to incidentid.
condtionToGetCase.AttributeName = "incidentid";
condtionToGetCase.Values = new string[] { EntityID.ToString() };
condtionToGetCase.Operator = ConditionOperator.Equal;
// Create the FilterExpression.
FilterExpression filterToGetCase = new FilterExpression();
// Set the properties of the FilterExpression.
filterToGetCase.FilterOperator = LogicalOperator.And;
filterToGetCase.Conditions.Add(condtionToGetCase);
// Create a column set that holds the names of the columns to be retrieved.
ColumnSet colsToGetCustomer = new ColumnSet();
colsToGetCustomer.AddColumn("title");
colsToGetCustomer.AddColumn("customerid");
// Create the QueryExpression.
QueryExpression queryToGetCase = new QueryExpression();
// Set the properties of the QueryExpression.
queryToGetCase.EntityName = EntityName.incident.ToString();
queryToGetCase.ColumnSet = colsToGetCustomer;
queryToGetCase.Criteria = filterToGetCase;
// Retrieve the cases/incidents.
BusinessEntityCollection cases = serviceSdk.RetrieveMultiple(queryToGetCase);
//Retrieve the case/incident.
if (cases.BusinessEntities.Count > 0)
{
regradingObject = (incident)cases.BusinessEntities[0];
}

No comments: