CRM 4.0 - extracting contact data from email address

Nobfeemnbek

New Member
I'm trying to use an email address to retrieve contact data. I'm already using this but i'm wondering how to extend it so that custom fields can also be returned:\[code\] public ContactInfo GetContactByEmail(string email, CrmService service) { QueryExpression query = new QueryExpression(); query.EntityName = "contact"; ColumnSet columns = new ColumnSet(); columns.Attributes.Add("contactid"); query.ColumnSet = columns; query.Criteria = new FilterExpression(); query.Criteria.FilterOperator = LogicalOperator.And; ConditionExpression condition = new ConditionExpression(); condition.AttributeName = "emailaddress1"; condition.Operator = ConditionOperator.Equal; condition.Values = new object[] { email.Trim() }; query.Criteria.Conditions.Add(condition); RetrieveMultipleRequest request = new RetrieveMultipleRequest(); request.Query = query; ContactInfo contactInfo = new ContactInfo(); RetrieveMultipleResponse response = null; response = (RetrieveMultipleResponse)service.Execute(request); foreach (contact cont in response.BusinessEntityCollection.BusinessEntities) { contactInfo.contactid = cont.contactid.Value; //Would also like to retrieve a custom attribute called ContactType (type int) } return contactInfo; }\[/code\]Any help or examples would be really appreciated. Thank you.
 
Back
Top