在2011年crm的Queryexpression中进行空检查

时间:2014-11-10 10:36:42

标签: dynamics-crm-2011 crm

我在CRM 2011中使用Queryexpression对象,我在条件语句中设置了null条件但是我发现了以下错误:

Condition for attribute 'customer_term_sheet.qdb_status': null is not a valid value for an attribute. Use 'Null' or 'NotNull' conditions instead.

请建议我,我该如何解决?

以下是我的代码:

QueryExpression qe = new QueryExpression();
qe.EntityName = "customer_term_sheet";
qe.ColumnSet = new ColumnSet(new string[] { "status" });

ConditionExpression CondOppId = new ConditionExpression();
CondOppId.AttributeName = "status";
CondOppId.Operator = ConditionOperator.Equal;

// This is the line in question
CondOppId.Values.Add(null);

FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions.AddRange(new ConditionExpression[] { CondOppId });
qe.Criteria = filter;
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = qe;
RetrieveMultipleResponse response = (RetrieveMultipleResponse)_serviceProxy.Execute(request);

1 个答案:

答案 0 :(得分:3)

使用ConditionOperator.Null,无需使用此运算符指定值。

ConditionExpression CondOppId = new ConditionExpression();
CondOppId.AttributeName = "qdb_status";
CondOppId.Operator = ConditionOperator.Null;