2009-06-23 35 views
0

我們使用的是MSCRM Dynamics,我們試圖讓一個特定用戶的所有孩子。 (一個用戶有一個經理,經理有'子女'。)以下工作,但如果用戶沒有子女則拋出異常。這可能起初似乎是合乎邏輯的,但爲什麼不只是返回一個空集呢?而且所有的東西都會拋出一個帶有「Invalid Argument」(這是錯誤的)神祕消息的SoapException,並且.Detail.InnerText會顯示「0x80040203爲ConditionOperator.In傳遞的值是空的平臺」。如果你看看相應的Response類,它有一個集合 - 爲什麼不把它留空?CRM:讓孩子在沒有孩子的情況下拋出異常

// 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)); 
} 

回答

2

我同意,它應該可能只是返回一個空的結果。我的猜測將在後面,執行請求或準備響應的一些步驟被翻譯爲QueryExpression。如果您使用使用ConditionOperator.InConditionExpression並將空白列表傳遞給QueryExpressions,那麼QueryExpressions會爆炸。因此,它可能是類似於它獲取子系統用戶GUID的列表(在某些情況下是空列表),然後嘗試使用另一個QueryExpression檢索該列表中的系統用戶的所有屬性,這就是拋出該異常的原因。

你也許可以設計一個你自己的QueryExpression或FetchXML,它可以爲你提供相同的結果,而不會在列表爲空時引發異常,或者只是捕獲異常並檢查特定的錯誤代碼,吞下去。

+0

我們正在吞嚥所有SoapExceptions,我真的覺得這是一個糟糕的解決方案。如果不能找到更好的解決方案,我將不得不在表達式中挖掘一下,看看我能否更好地隔離這種情況。 – Thanatos 2009-06-23 23:13:35

相關問題