2013-11-28 90 views
0

我正在嘗試創建一個自定義工作流程(對於Dynamics CRM 2011),該工作流程必須從報價中發送詳細報價信息的電子郵件。 我使用sdk在Visual Studio 2010中創建它。用c檢索報價詳細信息#

該工作流由引用手動觸發。 我能夠獲取客戶ID的價值,但我無法得到的附加文件或引用的quotedetails,當我啓動的工作流我有這樣的例外:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. 
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key) 
    at Microsoft.Xrm.Sdk.Entity.get_Item(String attributeName) 
    at CPageCRM.Workflow.QuoteSendMailNotificationRIP.Execute(CodeActivityContext executionContext) 

我的代碼是:

//to get the current Quote 
Entity preImageEntity = context.PreEntityImages.Values.FirstOrDefault(); 
//preImageEntity is a Quote because I trigger the workflow from a Quote 
//the next two lines work, I can retrieve the good value of the Quote 
string natureDevis = Utils.GetOptionSetValueLabel(service, preImageEntity, "new_nature", (OptionSetValue)preImageEntity["new_nature"]); 
string prospectDevis = ((EntityReference)preImageEntity["customerid"]).Name; 
//I get the exception after that : 
List<QuoteDetail> listQuoteDetail = new List<QuoteDetail>(); 
listQuoteDetail = preImageEntity["quote_details"] as List<QuoteDetail>; //I get the exception 

我不明白爲什麼在dictionnary不存在quote_details,因爲當我這樣做:

Quote devis = new Quote(); 

    devis.quote_details //<= (the autocompletion is working) 

我有同樣的問題當我嘗試獲取sharepointdocumentlocation

任何人都有說明?我如何從代碼中檢索報價細節和附在我的報價上的文件?

謝謝

回答

1

我用LINQ查詢 successed我不得不尋找其被鏈接到報價quote_detail:

var queryQuoteDetail = from r in orgServiceContext.CreateQuery("quotedetail") 
         where ((EntityReference)r["quoteid"]).Id.Equals(context.PrimaryEntityId) 
         select r; 
1

評論和潛在答案。

我的評論是當從圖像中檢索出東西時我經常發現讓編譯器抓住正確的類型並使用'var'更容易。

我的答案是,quote_details不只是一個字段,而是一個實際的1-n關係shsh(通過查看元數據瀏覽器)。您可能需要在單獨的檢索中獲取相關實體。

編輯: 例如:_service.Retrieve( 「報價」,quoteId,新ColumnSet( 「quote_details」))
將檢索服務的報價詳情。但是,您也可以檢查並查看是否傳遞了PreImage中的quote_details屬性。

+0

感謝YOUT評論, 我試着用_service.RetrieveMultiple得到quote_details但Ô得到了同樣的問題。 我必須使用LINQ查詢嗎?還是有另一種方法? – Mike

+0

我試過你說的: var entite = _service.Retrieve(「quote」,context.PrimaryEntityId,new ColumnSet(「quote_details」)); 但我收到了一條異常消息: 'Quote'實體不包含Name ='quote_details'的屬性。我試過了: var queryAccount2 = from orgServiceContext.CreateQuery(「quote」)中的r 其中((EntityReference)r [「quoteid」])。 當我嘗試r.Attributes.ToList();沒有關於報價的細節。 有什麼建議嗎? – Mike