我需要添加SalesLine
到现有的SalesOrder
. SalesOrder
还SalesLine
没有。我AIF
在 CSharp (C#) 中使用。我正在使用以下代码,但出现以下异常(通过 Dynamics AX 异常窗口检查)。
- 验证记录时发现错误。
- 更新已取消。
这是我的代码。
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 的新手。
请帮忙!谢谢你。