Skip to main content
Business Central forum
Answered

BC - coding problem

editSubscribe (0) ShareShare
ReportReport
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:
  • coding noob Profile Picture
    coding noob 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,984 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
  • coding noob Profile Picture
    coding noob 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?

  • coding noob Profile Picture
    coding noob 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"?

  • coding noob Profile Picture
    coding noob 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?

  • coding noob Profile Picture
    coding noob 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

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans