web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Invoice Discount error when creating Sales Order through web services

(0) ShareShare
ReportReport
Posted on by 3,013

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

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans