[英]Dynamics CRM 2015 Online: cannot retrive custom fields
The following code throws a KeyNotFoundException at WriteLine(): 以下代码在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());
}
}
}
I've already added new_customer_num and new_is_customer (required) fields to Contact entity. 我已经向联系人实体添加了new_customer_num和new_is_customer(必填)字段。 If I deliberately misspell them, then FaultException is thrown at service.RetrieveMultiple(query);
如果我故意拼错它们,则会在service.RetrieveMultiple(query);处抛出FaultException。 so I guess CRM "knows" my custom fields.
所以我猜CRM会“知道”我的自定义字段。 Then why doesn't query result include them?
那为什么查询结果中不包括它们呢?
Well, to make it work, I had to add a condition: 好吧,要使其正常工作,我必须添加一个条件:
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 }
},
},
}
};
SDK Doc for ColumnSet says that query returns only non-null values. ColumnSet的SDK文档说查询仅返回非null值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.