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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Not able to calculate GST

(2) ShareShare
ReportReport
Posted on by 12
Dear All,
I have written below code to create sales invoice in business central. through this code all the fields are updated in bussiness central but GST is not calculate. but i Re-Select location then its calculating GST .can anyone suggest ? 
 
 
 
 
procedure CreateSalesInvoice()
    begin
        SalesNReceivableSetup.Get();
        SalesHeaderRec.Reset();
        SalesHeaderRec.SetRange(/External Document No./, SalesStaging.InvoiceNo);
        if not SalesHeaderRec.FindFirst() then begin
            SalesHeader.Init();
            SalesHeader./No./ := NoSeriesMngt.GetNextNo(SalesNReceivableSetup./Invoice Nos./, WORKDATE, TRUE);
            SalesHeader.Validate(/No./);
            //To get Sell-To customer No++
            CustomerRec.Reset();
            CustomerRec.SetRange(ClientID, SalesStaging./Client ID/);
            CustomerRec.SetRange(/Application Type/, SalesStaging./Application Type/);
            if CustomerRec.FindFirst() then begin
                SalesHeader./Sell-to Customer No./ := CustomerRec./No./;
                //   SalesHeader./Sell-to Customer Name/:=CustomerRec.Name;
                SalesHeader.Validate(/Sell-to Customer No./);
            end;
            //--
            if SalesStaging.PaymentTerms <> '' then begin
                SalesHeader./Payment Terms Code/ := SalesStaging.PaymentTerms;
                SalesHeader.Validate(/Payment Terms Code/);
            end;
           
            SalesHeader./Document Type/ := SalesHeader./Document Type/::Invoice;
            SalesHeader.Validate(/Document Type/);
            // SalesHeader./Sell-to Customer Name/ := SalesStaging.ClientName;
            // SalesHeader.Validate(/Sell-to Customer No./);
            SalesHeader./Sell-to Address/ := SalesStaging.Address;
            SalesHeader.Validate(/Sell-to Address/);
            SalesHeader./Posting Date/ := SalesStaging.Createddate;
            SalesHeader.Validate(/Posting Date/);
            SalesHeader./Sell-to Address 2/ := CopyStr(SalesStaging.Address2, 1, 50);
            SalesHeader.Validate(/Sell-to Address 2/);
            SalesHeader./Payment Terms Code/ := SalesStaging.PaymentTerms;
            SalesHeader.Validate(/Payment Terms Code/);
            SalesHeader.Validate(/External Document No./);
            if SalesNReceivableSetup./Ho Location/ <> '' then begin
                SalesHeader./Location Code/ := SalesNReceivableSetup./Ho Location/;
                SalesHeader.Validate(/Location Code/);
            end;
            SalesHeader.Insert(true);
            if SalesNReceivableSetup./Ho Location/ <> '' then begin
                SalesHeader./Location Code/ := SalesNReceivableSetup./Ho Location/;
                SalesHeader.Validate(/Location Code/);
            end;
            SalesHeader.Modify();
            SalesLine.Init();
            SalesLine./Document Type/ := SalesLine./Document Type/::Invoice;
            SalesLine.Validate(/Document Type/);
            SalesLine./Document No./ := SalesHeader./No./;
            SalesLine.Validate(/Document No./);
            SalesLine./Line No./ := 10000;
            SalesLine.Validate(/Line No./);
            SalesLine.Type := SalesLine.Type::/G/L Account/;
            SalesLine.Validate(Type);
            SalesLine./No./ := CustomerRec./Sales Account/;
            SalesLine.Validate(/No./);
            
            SalesLine./Location Code/ := SalesHeader./Location Code/;
            SalesLine.Validate(/Location Code/);
            SalesLine.Quantity := SalesStaging.Completes;
            SalesLine.Validate(Quantity);
            SalesLine./Shortcut Dimension 2 Code/ := SalesStaging.Marketid;
            SalesLine.Validate(/Shortcut Dimension 2 Code/);

            SalesLine./Unit Price/ := SalesStaging.Cpi;
            SalesLine.Validate(/Unit Price/);
            SalesLine./GST Group Code/ := SalesStaging./GST Group Code/;
            SalesLine.Validate(/GST Group Code/);
            SalesLine./HSN/SAC Code/ := SalesStaging./HSN Code/;
            SalesLine.Validate(/HSN/SAC Code/);
              SalesLine.Insert(true);
    end;
 
 
 
 
 
 
 
 
 
  • Suggested answer
    Tabrez Ajaz Profile Picture
    793 on at

    Hi,

    GST is not calculating because the fields are being validated in the wrong sequence.

    In the sales line, Quantity and Unit Price are validated before GST Group Code and HSN/SAC Code. The Tax Engine is triggered during amount-related validations, but at that point the GST fields are blank. Re-selecting the location triggers validation again, so GST gets calculated.

    Please make these changes:

    1. Insert the Sales Header first.

    2. After insertion, validate Sell-to Customer No. and Location Code.

    3. On the Sales Line, validate GST Group Code and HSN/SAC Code before Quantity and Unit Price.

    4. Use Validate(Field, Value) instead of assigning a value and then calling Validate(Field).

    Recommended line sequence:
    SalesLine.Init();
    SalesLine."Document Type" := SalesHeader."Document Type";
    SalesLine."Document No." := SalesHeader."No.";
    SalesLine."Line No." := 10000;
    SalesLine.Validate(Type, SalesLine.Type::"G/L Account");
    SalesLine.Validate("No.", CustomerRec."Sales Account");
    SalesLine.Validate("Location Code", SalesHeader."Location Code");
    SalesLine.Validate("GST Group Code", SalesStaging."GST Group Code");
    SalesLine.Validate("HSN/SAC Code", SalesStaging."HSN Code");
    SalesLine.Validate(Quantity, SalesStaging.Completes);
    SalesLine.Validate("Unit Price", SalesStaging.Cpi);
    SalesLine.Insert(true);

     

    For the header, validate the location after inserting it:

    SalesHeader.Insert(true);

    if SalesNReceivableSetup."Ho Location" <> '' then

       SalesHeader.Validate(

            "Location Code",

            SalesNReceivableSetup."Ho Location");

    SalesHeader.Modify(true);

     

    Also verify that the Location has a valid GST Registration No. and State Code, and that the GST rate setup exists for the selected GST Group Code, HSN/SAC Code, and posting date.
     

    Best Regards,
    Tabrez Ajaz

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 720 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 436 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 409 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans