Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

BC - coding problem

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;


}
Categories:
  • 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,023 Moderator 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans