我在这里碰壁,试图通过 AIF(Dynamics AX webservices)更新 C# 中的销售订单
我有以下代码:
/// <summary>
/// Updates an order in AX
/// </summary>
/// <param name="order">Order to update</param>
public void UpdateOrder(SalesOrder order)
{
try
{
var client = new write.SalesOrderServiceClient();
var callContext = new write.CallContext() { Company = "mcompany" };
var entityKeyList = new write.EntityKey[1];
var entityKey = new write.EntityKey();
var keyField = new write.KeyField();
keyField.Field = "SalesId";
keyField.Value = order.orderCaseId;
entityKey.KeyData = new write.KeyField[1] { keyField };
entityKeyList = new write.EntityKey[1] { entityKey };
var salesOrder = new write.AxdSalesOrder
{
DocPurpose = write.AxdEnum_XMLDocPurpose.Original,
SalesTable = new write.AxdEntity_SalesTable[1],
};
salesOrder.SalesTable[0] = new write.AxdEntity_SalesTable
{
PurchOrderFormNum = order.purchaseOrderFormNumber,
ReceiptDateRequested = order.receiptDateRequested,
SalesLine =
new write.AxdEntity_SalesLine[order.salesOrderLines.Count()],
_DocumentHash = order.documentHash
};
var orderLinesArray = order.salesOrderLines.ToArray();
for (int i = 0; i < order.salesOrderLines.Count(); i++)
{
salesOrder.SalesTable[0].SalesLine[i] = new write.AxdEntity_SalesLine()
{
SalesQty = orderLinesArray[i].quantity,
SalesUnit = orderLinesArray[i].unit,
};
}
client.update(callContext, entityKeyList, salesOrder);
}
catch (Exception e)
{
Logging.AddLogEntry(e.Message);
}
}
要更新的 AX 订单的数据来自我的模型对象SalesOrder
,我尝试将其映射到 AxdSalesOrder 对象以传递给服务。
我不断收到以下异常:
The key field SalesId cannot be updated.
有谁知道我在这里做错了什么?:-)
提前致谢!