Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

BC - coding problem

(0) ShareShare
ReportReport
Posted on by 41

Hi,

I have a req to create a couple new fields on the "Bank Account List" page. 
one field is Selected Payments. For this , i used a Calcformula to tally all the payments made using each bank account. 

This works, here's my code 

tableextension 50125 BankAccountTableExtension extends "Bank Account"
{
    fields

    {

        field(50001; "Selected Payments"; Decimal)

        {

            Caption = 'Selected Payments';
            AutoFormatType = 1;
            CalcFormula = Sum("Gen. Journal Line".Amount WHERE("Bal. Account No." = FIELD("No.")));


            Editable = false;
            FieldClass = FlowField;

        }

    }
}
I have to create another field called "Projected Balance" 
This would be the Bank Account balance - Selected Payments
However, i can't seem to find anything online that would help with a "minus" function
This is what i have so far - it may be very wrong - but this is the first set of code i've written using AL.
Any assistance would be greatly appreciated.
tableextension 50126 ProjectedBalance extends "Bank Account"
{
    fields
    {
        field(50126; "Projected Balance"; Decimal)
        {
            Caption = 'Projected Balance';


        }
    }




    procedure GetProjectedBalance(var "Selected Payments": Decimal; var "Projected Balance": Decimal)
    begin
        CalcFields(Balance);
        "Selected Payments" := "Selected Payments";
        "Projected Balance" := Balance - "Selected Payments";
    end;


}
  • Rajiv Sewsarran Profile Picture
    Rajiv Sewsarran 41 on at
    RE: BC - coding problem

    Thank you for you assistance Nitin and Giambattista! much appreciated!

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,085 Super User 2024 Season 1 on at
    RE: BC - coding problem

    Hi,

    Please change your all code with below and check the image I pasted here.

    tableextension 50104 RS extends "Bank Account"
    {
        fields
        {
            field(50104; "Selected Pmts"; Decimal)
            {
                AutoFormatExpression = "Currency Code";
                AutoFormatType = 1;
                CalcFormula = Sum("Gen. Journal Line".Amount WHERE("Bal. Account No." = FIELD("No.")));
                Caption = 'Selected Pmts';
                Editable = false;
                FieldClass = FlowField;
            }
            // field(50102; "Proj Bal"; Decimal)
            // {
            //     Caption = 'Proj Bal';
            //     DataClassification = ToBeClassified;
            // }

        }
        procedure GetProjBal(): Decimal
        begin
            CalcFields(Balance, "Selected Pmts");
            exit(Rec.Balance - Rec."Selected Pmts");
        end;
    }
    pageextension 50103 "Proj Bal" extends "Bank Account List"
    {
        layout
        {
            addafter(BalanceAmt)
            {
                field("Proj Bal"; rec.GetProjBal())
                {
                    ApplicationArea = all;
                    Caption = 'Proj Bal';

                }
                field("Selected Pmts"; Rec."Selected Pmts")
                {
                    ApplicationArea = all;
                    Caption = 'Selected Pmts';
                }

            }
        }
    }
    pastedimage1652930823902v1.png
  • Rajiv Sewsarran Profile Picture
    Rajiv Sewsarran 41 on at
    RE: BC - coding problem

    Hi

    i no longer get that error , however the Proj Bal is still 0.00

    This is my code. 

    Thanks again for you assistance

    tableextension 50104 RS extends "Bank Account"
    {
        fields
        {
            field(50104; "Selected Pmts"; Decimal)
            {
                AutoFormatExpression = "Currency Code";
                AutoFormatType = 1;

                CalcFormula = Sum("Gen. Journal Line".Amount WHERE("Bal. Account No." = FIELD("No.")));


                Caption = 'Selected Pmts';
                Editable = false;
                FieldClass = FlowField;

            }
            field(50102; "Proj Bal"; Decimal)
            {
                Caption = 'Proj Bal';
                DataClassification = ToBeClassified;
            }

        }
        procedure GetProjBal() "Proj Bal": Decimal
        begin
            CalcFields(Rec.Balance);
            CalcFields(Rec."Selected Pmts");
            "Proj Bal" := Rec.Balance - Rec."Selected Pmts"
        end;
    }
    pageextension 50103 "Proj Bal" extends "Bank Account List"
    {
        layout
        {
            addafter(BalanceAmt)
            {
                field("Proj Bal"; Rec."Proj Bal")
                {
                    ApplicationArea = all;
                    Caption = 'Proj Bal';

                }
                field("Selected Pmts"; Rec."Selected Pmts")
                {
                    ApplicationArea = all;
                    Caption = 'Selected Pmts';
                }

            }
        }
    }


  • RE: BC - coding problem

    you have 2 choose to choose the same table?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans