The following code sample shows how to delete a line of an existing sales order through AIF from outside Dynamics AX 2012 . It uses a partial update, which means that we don’t have to send the whole document back to AX. As the documentation says, we have to include just the fields to change (none in my case) and “any fields required by the document” – that’s why I included fields such as PurchOrderFormNum. Note that you may have different fields set as mandatory.
Also notice how action properties are specified – we’re deleting the line, which means updating the order.
staticvoid Main(string[] args){using(SalesOrderServiceClient client =new SalesOrderServiceClient()){ EntityKey[] entityKeyList = EntityKeyForSalesId("SO00001"); // Get the order to modifyvar order = client.read(new CallContext(), entityKeyList); // For demo, always the last order line is deletedvar lastLine = order.SalesTable[0].SalesLine.Last(); var salesLine =new AxdEntity_SalesLine(){ RecId = lastLine.RecId, RecIdSpecified =true, SalesUnit = lastLine.SalesUnit, action = AxdEnum_AxdEntityAction.delete, actionSpecified =true}; var salesTable =new AxdEntity_SalesTable(){ _DocumentHash = order.SalesTable[0]._DocumentHash, PurchOrderFormNum = order.SalesTable[0].PurchOrderFormNum, ReceiptDateRequested = order.SalesTable[0].ReceiptDateRequested, action = AxdEnum_AxdEntityAction.update, actionSpecified =true, SalesLine =new[]{ salesLine }}; AxdSalesOrder newOrder =new AxdSalesOrder(){ SalesTable =new[]{ salesTable }}; // Update the order client.update(new CallContext(), entityKeyList, newOrder);}} // Helper methodprivatestatic EntityKey[] EntityKeyForSalesId(string salesId){ KeyField field =new KeyField(){ Field ="SalesId", Value= salesId }; EntityKey key =new EntityKey(){ KeyData =new[]{ field }}; returnnew[]{ key };}