i want to cancel the order from .net using AIF service in dunamics ax 2009.
////// here is my code
this code is not working, throwing exception : “The key field SalesId cannot be updated”
[WebMethod]
public void salesorderCancel()
{
SalesOrderServiceClient salesService = new SalesOrderServiceClient();
AxdSalesOrder axdsales = new AxdSalesOrder();
AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();
AxdEntity_SalesLine[] SalesLine = new AxdEntity_SalesLine[10];
EntityKey key = new EntityKey();
EntityKey[] keys = new EntityKey[1];
KeyField fld = new KeyField();
fld.Field = “SalesId”;
fld.Value = “00000342_032”;
key.KeyData = new KeyField[] { fld };
keys = new EntityKey[] { key };
AxdSalesOrder TempSalesOrderObj = salesService.read(keys);
AxdEntity_SalesTable[] TempSalesTable = TempSalesOrderObj.SalesTable;
salesTable.ReceiptDateRequested = TempSalesTable[0].ReceiptDateRequested;
salesTable.PurchOrderFormNum = “1”;
salesTable._DocumentHash = TempSalesTable[0]._DocumentHash;
salesTable.action = AxdEnum_AxdEntityAction.update;
salesTable.actionSpecified = true;
SalesLine[0] = new AxdEntity_SalesLine();
SalesLine[0].actionSpecified = true;
SalesLine[0].action = AxdEnum_AxdEntityAction.update;
SalesLine[0].RecIdSpecified = true;
SalesLine[0].RecId = TempSalesTable[0].SalesLine[0].RecId;
SalesLine[0].RecVersionSpecified = true;
SalesLine[0].RecVersion = TempSalesTable[0].SalesLine[0].RecVersion;
SalesLine[0].ItemId = “T0063”;
//SalesLine[0].SalesQty = Convert.ToDecimal(“4”);
SalesLine[0].SalesUnit = “EACH”;
SalesLine[0].RemainInventPhysicalSpecified = true;
SalesLine[0].RemainInventPhysical = Convert.ToDecimal(“0”);
SalesLine[0].RemainSalesPhysicalSpecified = true;
SalesLine[0].RemainSalesPhysical = Convert.ToDecimal(“0”);
salesTable.SalesLine = new AxdEntity_SalesLine[] { SalesLine[0] };
axdsales.SalesTable = new AxdEntity_SalesTable[] { salesTable };
salesService.update(keys, axdsales);
// salesLine.RemainInventPhysical = 0;
// salesLine.RemainSalesPhysicalSpecified = true;
// salesLine.RemainSalesPhysical = 0;
// salesTable.SalesLine = new AxdEntity_SalesLine[]{ salesLine };
// axdsales.SalesTable = new AxdEntity_SalesTable[] { salesTable };
// salesService.update(call, keys, axdsales);
//// salesService.update(call, AxEntityKey, axdsales);
}
please help me out.
thanks.