2017-09-18 92 views
0

我需要將SalesLine添加到現有的SalesOrderSalesOrder還沒有任何SalesLine呢。我在CSharp(C#)中使用了AIF。我正在使用以下代碼,但我正在接受以下異常(通過Dynamics AX異常窗口進行檢查)。將新銷售線添加到現有SalesOrder - MS Dynamics AX 2012 - AIF(C#)

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

請幫忙!謝謝。

+0

這會有所幫助。在你的情況下,你正在更新標題和插入行,即部分更新。 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 –

+0

我已經通過這些鏈接。事實上,我的代碼是基於這些鏈接,但它不工作,並提供**更新已被取消。** –

+0

刪除下面兩行,因爲我認爲這不是必需的。 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; –

回答

0

在你的情況下,你正在更新標題和插入行,即部分更新。代碼示例請參閱下面的鏈接。 Updating a salesorder using AIF https://community.dynamics.com/ax/b/goshoom/archive/2014/01/21/creating-sales-orders-via-aif-in-ax2012

在你的代碼,我suggets,因爲我覺得這不需要刪除下面兩行。

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/