Retrieving a single Guid in CRM 4.0
- by user1746560
I'm new to CRM (version 4.0) and i'm trying to return a 'yearid' guide based on a given year (which is also stored in the entity).So far i've got:
public static Guid GetYearID(string yearName)
{
ICrmService service = CrmServiceFactory.GetCrmService();
// Create the query object.
QueryExpression query = new QueryExpression("year");
ColumnSet columns = new ColumnSet();
columns.AddColumn("yearid");
query.ColumnSet = columns;
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.AddCondition(new ConditionExpression
{
AttributeName = "yearName",
Operator = ConditionOperator.Equal,
Values = new object[] { yearName}
});
query.Criteria = filter;
}
But my questions are:
A) What code do in addition to this to actually store the Guid?
B) Is using a QueryExpression the most efficient way to do this?