'Unexpected error occurred Platform' - 这可能是由于错误地查询了一个选择列表吗?
'Unexpected error occurred Platform' - could this be due to incorrectly querying a picklist?
我正在尝试 return 来自自定义实体的 'team members' 列表,其中它们的角色与特定值列表相匹配。我试图匹配的属性是一个选择列表,我想知道这是否导致了我的错误。这是我的代码:
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此处不允许 [])。
当涉及到比较时,您的代码令人窒息:选项列表值的类型为 int
,但您正在提供 string
s。一旦类型匹配,它应该可以工作。
我正在尝试 return 来自自定义实体的 'team members' 列表,其中它们的角色与特定值列表相匹配。我试图匹配的属性是一个选择列表,我想知道这是否导致了我的错误。这是我的代码:
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此处不允许 [])。
当涉及到比较时,您的代码令人窒息:选项列表值的类型为 int
,但您正在提供 string
s。一旦类型匹配,它应该可以工作。