'平台发生意外错误' - 尝试使用带有NotNull运算符的条件表达式

时间:2015-02-03 11:51:08

标签: c# dynamics-crm dynamics-crm-4

我正在尝试返回“opps”列表,其中2个字段中的任何一个都有值。所以我想我可以简单地使用'NotNull条件运算符。但是,这似乎不起作用。我正在检查的字段被指定为Guid字段,但实际上返回了查找。所以基本上,如果它没有设置为任何它是null,否则在那里有一个查找(不是一个特定的值)。我怀疑NotNull运算符因此仍然可以工作,但似乎并非如此。这是我的代码:

public static BusinessEntityCollection GetOpps(string NewBU)
{
    ColumnSet cols = new ColumnSet();
    string oldBU1 = "";
    string oldBU2 = "";

    switch (NewBU)
    {
        case "NewBUA":
            oldBU1 = "field_Abuid";
            oldBU2 = "field_Bbuid";
            cols.Attributes = new string[] { "id", oldBU1, oldBU2 };
                break;
        case "NewBUB":
            oldBU1 = "field_Cbuid";
            oldBU2 = "field_Dbuid";
            cols.Attributes = new string[] { "id", oldBU1, oldBU2 };
            break;
    }

    QueryExpression query = new QueryExpression();
    query.EntityName = "MyEntity";
    query.ColumnSet = cols;

    ConditionExpression ce = new ConditionExpression();
    ce.AttributeName = oldBU1;
    ce.Operator = ConditionOperator.NotNull;

    ConditionExpression ce2 = new ConditionExpression();
    ce2.AttributeName = oldBU2;
    ce2.Operator = ConditionOperator.NotNull;

    FilterExpression filter = new FilterExpression();
    filter.Conditions = new ConditionExpression[] { ce, ce2 };
    filter.FilterOperator = LogicalOperator.Or;

    query.Criteria = filter;

    BusinessEntityCollection MyCollection = new BusinessEntityCollection();

    try
    {
        using (crmService)
        {
            MyCollection = crmService.RetrieveMultiple(query);
        }
    }
    catch (SoapException se)
    {
        throw new Exception("Error occurred retrieving opps for " + NewBU + ". " + se.Detail.InnerXml);
    }
    catch (Exception ex)
    {
        throw new Exception("Error occurred retrieving opps for " + NewBU + ". " + ex.Message);
    }

    return MyCollection;
}

我很确定这是2个条件表达式,因为我已经删除了它们,只是根据guid返回一个特定的opp并且它工作(并在指定的字段中显示一个查找)。所以,如果我的假设是正确的,为什么我得到错误,我如何检查字段并返回opps,其中任何一个字段不为空?

0 个答案:

没有答案