Skip to main content

Notifications

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

Update Totals on Subform

Posted on by 350

I have created 2 fields by extending the Sales Line table.

  1. Premium % (Decimal)
  2. Premium Amount (Decimal)

These two fields will be shown on the Sales Order Subform and will function like how Line Discount % works. It is just that, it will add the Premium Amount value to the Line Amount instead how Discount % subtracts Line Discount Amount from Line Amount.

Here is the code I have written on the Sales Order Subform;

layout
    {
        addafter("Line Discount %")
        {
            field("Premium %"; "Premium %")
            {
                ApplicationArea = All;
                BlankZero = true;
                trigger OnValidate()
                begin
                    Update_Premium_Amount();
                end;
            }
            field("Premium Amount"; "Premium Amount")
            {
                ApplicationArea = All;
                BlankZero = true;
                trigger OnValidate()
                begin
                    Update_Premium_Percentage();
                end;
            }
        }

    }
    
    
    
     local procedure Update_Premium_Amount()
    var
        percValue: Decimal;
    begin
        Clear(percValue);
        percValue := rec."Premium %" / 100;
        rec."Premium Amount" := rec."Line Amount" * percValue;
        rec."Line Amount" := rec."Line Amount"   rec."Premium Amount";
        CurrPage.Update();
        UpdateAmounts();
        CalcLineAmount();
    end;

    local procedure Update_Premium_Percentage()
    begin
        if rec."Line Amount" <> 0 then begin
            rec."Premium %" := (rec."Premium Amount" * 100) / rec."Line Amount";
            rec."Line Amount" := rec."Line Amount"   rec."Premium Amount";
        end;
        CurrPage.Update();
        UpdateAmounts();
        CalcLineAmount();
    end;

My Subtotal Excl. VAT on the Subform gets updated, however, Total Excl VAT and Total Incl. VAT remains unchanged. Now I can't figure out how solve this.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Update Totals on Subform

    Try validating the Line Amount field instead of assigning the value, are you referring the Amount Including VAT on the line?  what is the VAT Calculation Type on the line?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans