'平台发生了意外错误' - 这可能是由于错误地查询了一个选项列表吗?

时间:2015-01-30 12:39:19

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

我正在尝试从自定义实体返回“团队成员”列表,其中他们的角色与特定值列表匹配。我想要匹配的属性是一个选项列表,我想知道这是否导致我的错误。这是我的代码:

public static BusinessEntityCollection GetTeamMembers(string BU, string[] roles)
{
    BusinessEntityCollection TeamMembers = new BusinessEntityCollection();

    ColumnSet cols = new ColumnSet();
    cols.Attributes = new string[] { "new_teamid", "new_id", "new_name", "ownerid", "new_rolepicklist" };

    QueryExpression query = new QueryExpression();
    query.ColumnSet = cols;
    query.EntityName = EntityName.new_team.ToString();

    List<ConditionExpression> ceList = new List<ConditionExpression>();

    foreach (string role in roles)
    {
        //I suspect it this block is where the problem occurs as 'new_rolepicklist' is a picklist, and 'role' will be something like 'Manager' (a picklist value).
        ConditionExpression ce2 = new ConditionExpression();
        ce2.AttributeName = "new_rolepicklist";
        ce2.Operator = ConditionOperator.Like;
        ce2.Values = new string[]{role};

        ceList.Add(ce2);
    }

    FilterExpression filter = new FilterExpression();
    filter.Conditions = ceList.ToArray();
    filter.FilterOperator = LogicalOperator.Or;
    query.Criteria = filter;

    try
    {
        using (crmService)
        {
            TeamMembers = crmService.RetrieveMultiple(query); //ERROR
        }
    }
    catch (SoapException se)
    {
        throw new Exception("Error occurred retrieving Team Members for " + BU + ". " + se.Detail.InnerXml);
    }
    catch (Exception ex)
    {
        throw new Exception("Error occurred retrieving Team Members for " + BU + ". " + ex.Message);            
    }

    return TeamMembers;
}

首先,有什么明显可能导致此错误吗?其次,如果是选项列表部分,我该如何解决?如何查询具有选项列表值的选项列表属性?

更新

按照Alex的正确答案,为了完成,我编辑了我的方法以获取int []角色以及foreach(角色中的int角色)和ce2.Values = new object [] {role}(int []不是允许在这里)。

1 个答案:

答案 0 :(得分:2)

在比较时,您的代码令人窒息:选项列表值的类型为int,但您正在提供string s。一旦匹配类型,它应该可以工作。