0

我正在尝试使用电子邮件地址来检索联系人数据。我已经在使用它,但我想知道如何扩展它以便也可以返回自定义字段:

    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;
    }

任何帮助或示例将不胜感激。谢谢你。

4

1 回答 1

0

您只需要向 中添加其他值ColumnSet,例如

ColumnSet columns = new ColumnSet();
columns.Attributes.Add("new_contacttype");

注意:这里的名称应该是架构而不是显示。

例子:

于 2013-01-27T21:52:08.233 回答