0

我需要添加SalesLine到现有的SalesOrder. SalesOrderSalesLine没有。我AIF在 CSharp (C#) 中使用。我正在使用以下代码,但出现以下异常(通过 Dynamics AX 异常窗口检查)。

  1. 验证记录时发现错误。
  2. 更新已取消。

这是我的代码。

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 的新手。

请帮忙!谢谢你。

4

1 回答 1

0

在您的情况下,您正在更新标题和插入行,即部分更新。请参阅以下链接以获取代码示例。 使用 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;

为集成端口配置故障排除选项,以便您可以验证日志。 https://technet.microsoft.com/en-us/library/hh202045.aspx

请验证文档日志和异常日志以查看传递给 Ax 的值。 https://technet.microsoft.com/en-us/library/aa834439.aspx https://technet.microsoft.com/en-us/library/aa834351.aspx

要调试 AIF,请参阅 msdn 博客。 https://blogs.msdn.microsoft.com/axsupport/2012/06/04/debugging-services-in-ax-2012/

于 2017-09-20T18:58:20.257 回答