我正在嘗試創建一個自定義工作流程(對於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
任何人都有說明?我如何從代碼中檢索報價細節和附在我的報價上的文件?
謝謝
感謝YOUT評論, 我試着用_service.RetrieveMultiple得到quote_details但Ô得到了同樣的問題。 我必須使用LINQ查詢嗎?還是有另一種方法? – Mike
我試過你說的: 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