我需要將SalesLine
添加到現有的SalesOrder
。 SalesOrder
還沒有任何SalesLine
呢。我在CSharp(C#)中使用了AIF
。我正在使用以下代碼,但我正在接受以下異常(通過Dynamics AX異常窗口進行檢查)。將新銷售線添加到現有SalesOrder - MS Dynamics AX 2012 - AIF(C#)
- 驗證記錄時發現錯誤。
- 更新已被取消。
這是我的代碼。
protected void Page_Load(object sender, EventArgs e)
{
try
{
SalesOrderCreateReadFindUpdateDelete.KeyField keyField = new SalesOrderCreateReadFindUpdateDelete.KeyField() { Field = "SalesId", Value = "SO-015749" };
SalesOrderCreateReadFindUpdateDelete.EntityKey entityKey = new SalesOrderCreateReadFindUpdateDelete.EntityKey();
entityKey.KeyData = new SalesOrderCreateReadFindUpdateDelete.KeyField[1] { keyField };
SalesOrderCreateReadFindUpdateDelete.EntityKey[] entityKeys = new SalesOrderCreateReadFindUpdateDelete.EntityKey[1] { entityKey };
SalesOrderCreateReadFindUpdateDelete.SalesOrderServiceClient _Client;
using (_Client = new SalesOrderCreateReadFindUpdateDelete.SalesOrderServiceClient())
{
SalesOrderCreateReadFindUpdateDelete.CallContext _callContext = new SalesOrderCreateReadFindUpdateDelete.CallContext();
_callContext.Company = "ART";
SalesOrderCreateReadFindUpdateDelete.AxdSalesOrder _SalesOrderList = _Client.read(_callContext, entityKeys);
SalesOrderCreateReadFindUpdateDelete.AxdEntity_SalesTable _SalesOrderTable = _SalesOrderList.SalesTable.First();
SalesOrderCreateReadFindUpdateDelete.AxdEntity_SalesLine salesLine = new SalesOrderCreateReadFindUpdateDelete.AxdEntity_SalesLine();
salesLine.ItemId = "PF507028";
salesLine.SalesQty = 1;
salesLine.SalesUnit = "ea";
salesLine.SalesId = "SO-015749";
salesLine.RecId = _SalesOrderTable.RecId;
salesLine.RecVersion = _SalesOrderTable.RecVersion;
SalesOrderCreateReadFindUpdateDelete.AxdEntity_InventDim inventDim = new SalesOrderCreateReadFindUpdateDelete.AxdEntity_InventDim();
inventDim.InventSiteId = "1";
inventDim.InventLocationId = "13";
salesLine.InventDim = new SalesOrderCreateReadFindUpdateDelete.AxdEntity_InventDim[1] { inventDim };
_SalesOrderTable.SalesLine = new SalesOrderCreateReadFindUpdateDelete.AxdEntity_SalesLine[1] { salesLine };
_Client.update(_callContext, entityKeys, _SalesOrderList);
lblOutput.Text += "<br />Success";
}
}
catch (Exception ex)
{
lblOutput.Text += "<br />Exception: " + ex.Message;
}
}
我錯過了什麼或做錯了什麼?如果我必須提供更多的字段,那麼可以在MS Dynamics中檢查這些必填字段。我是MS Dynamics的新手。
請幫忙!謝謝。
這會有所幫助。在你的情況下,你正在更新標題和插入行,即部分更新。 https://stackoverflow.com/questions/20049220/updating-a-salesorder-using-aif https://community.dynamics.com/ax/b/goshoom/archive/2014/01/21/creating-sales-orders -via-aif-in-ax2012 –
我已經通過這些鏈接。事實上,我的代碼是基於這些鏈接,但它不工作,並提供**更新已被取消。** –
刪除下面兩行,因爲我認爲這不是必需的。 salesLine.RecId = _SalesOrderTable.RecId; salesLine.RecVersion = _SalesOrderTable.RecVersion; 修改以下行以確保相同的銷售訂單得到更新。 salesLine.SalesId = _SalesOrderTable.SalesId; 添加以下四行進行部分更新。 _SalesOrderTable.action = AxdEnum_AxdEntityAction.update; _SalesOrderTable。actionSpecified = true; salesLine.action = AxdEnum_AxdEntityAction.create; salesLine.actionSpecified = true; –