Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

BC - coding problem

Posted on by 35

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 35 on at
    RE: BC - coding problem

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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,991 Super User 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 35 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?

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

    yup field name is correct i created a new one called Selected Pmts

  • RE: BC - coding problem

    Field name is correct? Field Name is "Selected Payments" or "Selected Pmts"?

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

    its on the tableextension

    error AL0132: 'Record "Bank Account"' does not contain a definition for 'Selected Pmts'

  • RE: BC - coding problem

    Were is the error?

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

    Hi, thanks for replying.

    I'm getting a new error now

    error AL0132: 'Record "Bank Account"' does not contain a definition for 'Selected Pmts'

    I uninstalled the extension and created a new one from scratch

    The field appears on the Bank Account list and is calculating as it should

    But when i try to do the new Tableextension for the Projected Balance i get this error

  • Suggested answer
    RE: BC - coding problem

    You can Try:

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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans