繁体   English   中英

Dynamics CRM 2015 Online:无法检索自定义字段

[英]Dynamics CRM 2015 Online: cannot retrive custom fields

以下代码在WriteLine()上引发KeyNotFoundException:

CrmConnection crmConnection = CrmConnection.Parse(_connectionString);
using (OrganizationService service = new OrganizationService(crmConnection))
{
    QueryExpression query = new QueryExpression
    {
        EntityName = "contact",
        ColumnSet = new ColumnSet("fullname", "new_customer_num", "new_is_customer"),
    };

    EntityCollection contacts = service.RetrieveMultiple(query);
    if (contacts.Entities.Count > 0)
    {
        foreach (var e in contacts.Entities)
        {
            System.Diagnostics.Debug.WriteLine(
                e.Attributes["fullname"].ToString() + "; " + 
                e.Attributes["new_is_customer"].ToString());
        }
    }
}

我已经向联系人实体添加了new_customer_num和new_is_customer(必填)字段。 如果我故意拼错它们,则会在service.RetrieveMultiple(query);处抛出FaultException。 所以我猜CRM会“知道”我的自定义字段。 那为什么查询结果中不包括它们呢?

好吧,要使其正常工作,我必须添加一个条件:

QueryExpression query = new QueryExpression
{
    EntityName = "contact",
    ColumnSet = new ColumnSet("fullname", "ht_customer_num", "ht_is_customer"),
    Criteria = new FilterExpression
    {
        Conditions = 
        {
            new ConditionExpression
            {
                AttributeName = "new_is_customer",
                Operator = ConditionOperator.Equal,
                Values = { true }
            },
        },
    }
};

ColumnSet的SDK文档说查询仅返回非null值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM