我使用Silverlight鄰數據服務從我的應用程序 與CRM 2011年進行互動當我嘗試將數據保存在實體SalesOrder如下:的Silverlight -CRM2011:貨幣發行不能爲空
Private void beginSave()
{
SalesOrder orderHeader = new SalesOrder();
orderHeader.TransactionCurrencyId = new EntityReference(){ Id = new Guid("77D695B5-ACB4-E111-97BC-00155D55B216"), LogicalName="transactioncurrency" };
orderHeader.AccountId = new EntityReference() { Id = new Guid(MyClassGeneralOrder.customerId), LogicalName = "account" };
orderHeader.Name = "My Name";
Money totalAmount = new Money(); Money totalAmountBase = new Money();
Money totalTaxe = new Money(); Money totalAmountLessFreight = new Money();
totalAmount.Value = (decimal)MyClassGeneralOrder.InvoiceTotal;
totalAmountBase.Value = (decimal)MyClassGeneralOrder.totalRetail;
totalTaxe.Value = (decimal)MyClassGeneralOrder.totalCharges;
totalAmountLessFreight.Value = (decimal)MyClassGeneralOrder.totalNet;
orderHeader.TotalAmount = totalAmount;
orderHeader.TotalAmount_Base = totalAmountBase;
orderHeader.TotalTax = totalTaxe;
orderHeader.TotalAmountLessFreight = totalAmountLessFreight;
orderHeader.Description = element.Name;
orderHeader.PriceLevelId = new EntityReference() { Id = new Guid("03C5C4CB-EBD0-E111-8140-00155D55B216"), LogicalName="pricelevel" };
_context.AddToSalesOrderSet(orderHeader);
_context.BeginSaveChanges(SaveCallback, orderHeader);
}
private void SaveCallback(IAsyncResult result)
{
_context.EndSaveChanges(result);
}
在我的函數EndSaveChanges(result),我收到此錯誤消息::«貨幣不能爲空»。 我不明白爲什麼,因爲我的「orderHeader.TransactionCurrencyId」字段不爲空。
你正在使用硬編碼Guid的事實看起來很奇怪。 – ChrisF
對於TransactionCurrencyId硬編碼Guid確實是一個糟糕的主意。 [此論壇主題](http://social.microsoft.com/Forums/en/crm/thread/dc4ad6d3-b75b-449f-9df5-6b972d0abd43)說明如何以編程方式檢索Guid。 –
嗨Sandta沃爾特斯,像論壇說,最好的辦法是聯繫[「transactioncurrencyid」] =新的EntityReference(「transactioncurrency」,新的Guid(「9D2A622D-CD69-E011-9321-00155D042416」)); – wben