0

我们正在使用 MSCRM Dynamics,并且我们正在尝试获取特定用户的所有孩子。(用户有一个经理,经理有“孩子”。)以下工作,但如果用户没有孩子,则会引发异常。起初这似乎是合乎逻辑的,也许,但为什么不只返回一个空集呢?最重要的是,它会抛出一个带有“无效参数”(这是错误的)的神秘消息的 SoapException,并且 .Detail.InnerText 显示“0x80040203 传递给 ConditionOperator.In 的值是空平台”。如果您查看相应的 Response 类,它有一个集合——为什么不把它留空呢?

// Create the request object.
RetrieveAllChildUsersSystemUserRequest retrieve =
    new RetrieveAllChildUsersSystemUserRequest();

// Create the column set object that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
cols.EntityName = "systemuserid";

// Set the column set.
retrieve.ColumnSet = cols;

// Set the ID of the parent user.
retrieve.EntityId = context.UserId;

RetrieveAllChildUsersSystemUserResponse retrieved =
    new RetrieveAllChildUsersSystemUserResponse();

/// Execute the request.
/// Catches if user does not have children
/// (Check to see if user is manager)

try
{
    retrieved =
        (RetrieveAllChildUsersSystemUserResponse)crmService.Execute(retrieve);
}
catch (System.Web.Services.Protocols.SoapException e)
{
    throw new Exception(string.Format("{0}", e.Detail.InnerText));
}
4

1 回答 1

2

我同意,它可能应该只返回一个空结果。我的猜测是在幕后,执行请求或准备响应的某些步骤被转换为QueryExpression. ConditionExpression如果您使用 a that usesConditionOperator.In并且您将其传递给一个空列表,则 QueryExpressions 会爆炸。因此,它可能类似于获取子系统用户 guid 的列表,在某些情况下是一个空列表,然后尝试使用另一个列表检索该列表中系统用户的所有属性,QueryExpression这就是引发异常的原因。

您可能可以QueryExpression自己设计一个或 FetchXML 来获得相同的结果,而不会在列表为空时引发异常的副作用,或者只是捕获异常并检查该特定错误代码并将其吞下。

于 2009-06-23T18:59:54.880 回答