So I'm creating a a SalesOrder with some Lines using the SOAP Page type web service. I get "'You cannot make any changes to the database until a Transaction has been started'."
This is my code in C#
public async Task<Create_Result> Post([FromBody] SalesHeader data) { SalesOrder_PortClient order = new SalesOrder_PortClient(); SalesOrder SalesOrder = new SalesOrder(); SalesOrder.Sell_to_Customer_No = data.CustNo; int i = 0; SalesOrder.SalesLines = new Sales_Order_Line[data.SalesLines.Length]; foreach (SalesLine l in data.SalesLines) { SalesOrder.SalesLines[i] = new Sales_Order_Line(); SalesOrder.SalesLines[i].Type = NavSalesOrderService.Type.Item; SalesOrder.SalesLines[i].TypeSpecified = true; SalesOrder.SalesLines[i].No = l.itemno; SalesOrder.SalesLines[i].Quantity = l.qty; SalesOrder.SalesLines[i].QuantitySpecified = true; SalesOrder.SalesLines[i].Location_Code = l.location; i++; } Create c = new Create(); c.SalesOrder = SalesOrder; Create_Result res = new Create_Result(); res = await order.CreateAsync(c); return res; }
So I create header and lines in single call. The problem I have is with the Invoice Discount.
In Sales Order Subform we have
OnAfterGetCurrRecord() CalculateTotals;
This takes us to
[External] CalcInvDisc() SalesCalcDiscount.CalculateInvoiceDiscountOnLine(Rec);
And finally to:
LOCAL CalculateInvoiceDiscount(VAR SalesHeader : Record "Sales Header";VAR SalesLine2 : Record "Sales Line") SalesSetup.GET; IF UpdateHeader THEN SalesHeader.FIND; // To ensure we have the latest - otherwise update fails. OnBeforeCalcSalesDiscount(SalesHeader); WITH SalesLine DO BEGIN LOCKTABLE; //THIS LINE THROWS TRANSACTION ERROR <<<<<------------------------------------------------!!!!! SalesHeader.TESTFIELD("Customer Posting Group"); CustPostingGr.GET(SalesHeader."Customer Posting Group"); SalesLine2.RESET; SalesLine2.SETRANGE("Document Type","Document Type"); SalesLine2.SETRANGE("Document No.","Document No."); SalesLine2.SETRANGE("System-Created Entry",TRUE); SalesLine2.SETRANGE(Type,SalesLine2.Type::"G/L Account"); SalesLine2.SETRANGE("No.",CustPostingGr."Service Charge Acc."); IF SalesLine2.FINDSET(TRUE,FALSE) THEN REPEAT
Any one got this error before. Any solutions?
'You cannot make any changes to the database until a Transaction has been started'.
*This post is locked for comments