Monday, May 14, 2007

CRM 3.0: Using QueryExpressionHelper to get a Contact's GUID

Here is an example of how to use QueryExpressionHelp to get a Contact's GUID.


QueryExpressionHelper queryHelper = new QueryExpressionHelper(EntityName.contact);
queryHelper.Columns.AddColumn("contactid");
queryHelper.Criteria.Conditions.AddCondition("FieldNameFromEntity", ConditionOperator.Equal, thisIsTheParameter);
queryHelper.Criteria.FilterOperator = LogicalOperator.And;
BusinessEntityCollection coll = service.RetrieveMultiple(queryHelper.Query);
contact user = (contact)coll.BusinessEntities[0];
Guid syscoGuid = user.contactid.Value.ToString();

No comments: