Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

How to calculate Invoice discount on sales orders

Posted on by 73
Hello All, I want to calculate invoice discount when creating sales orders through customization.I have written below code to update /Invoice discount/ field on sales orders but its not working. Can anyone suggest how to update invoice discount after creating sales orders.
 
 
        //To update invoice discount++
        SalesHeader2.Reset();
        SalesHeader2.SetRange(/External Document No./, LocationGUID);
        if SalesHeader2.FindSet() then begin
            repeat
                OrderDiscountAmt1 := 0;
                SalespossierBridge5.Reset();
                SalespossierBridge5.SetRange(/Sales Order No./, SalesHeader2./No./);
                SalespossierBridge5.SetFilter(Discount_discounts, '<>%1', '');
                if SalespossierBridge5.FindSet() then begin
                    repeat
                        Evaluate(OrderDiscountAmt, SalespossierBridge5.Discount_discounts);
                        OrderDiscountAmt1 += OrderDiscountAmt;
                    until SalespossierBridge5.Next() = 0;
 
                    SalesHeader2./Invoice Discount Calculation/ := SalesHeader2./Invoice Discount Calculation/::Amount;
                    SalesHeader2./Invoice Discount Value/ := OrderDiscountAmt1;
                    SalesHeader2.Modify();
 
                end;
            until SalesHeader2.Next() = 0;
        end;
        //
Categories:
  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,114 Super User 2024 Season 2 on at
    How to calculate Invoice discount on sales orders
    What value do you have in LocationGUID?
    Is that same value is there in External Document No. field of Sales Header?
    Please add messages in some places and check whether your code is hitting those places or not.
    Or better to debug.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,134 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,928 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans