Skip to main content

Notifications

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

procedure to switch a field options in a factbox

Posted on by 465

Hi Community,

I am trying to connect line type in planning job to show fields in a factbox, but when I change the status budget for billable is not matching.

Could you help me with this issue?

I will appreciate, 

Thank you

pastedimage1676640306546v3.png

This is the code that I write:

pastedimage1676640935659v4.png

trigger OnAfterGetCurrRecord() // after get a record sum totals
    begin
        if rec."Line Type" = Rec."Line Type"::Budget then begin
            Rec.CalcSums("Total Cost");
            Rec.CalcSums("Line Amount");
            Rec.CalcSums("Net Margin");
            //Rec.CalcSums("Invoiced Amount (LCY)");
            TotalCostPlanningLine := Rec."Total Cost";
            TotalBudgetLineAmount := Rec."Line Amount";
            TotalNetMargin := Rec."Net Margin";

        end;
    end;

    var //Globals variables
        TotalBudgetLineAmount: Decimal;
        TotalCostPlanningLine: Decimal;
        TotalNetMargin: Decimal;
Categories:
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: procedure to switch a field options in a factbox

    Why not do a calcfields in the OnAfterGetRecord trigger regardless of the status?

  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: procedure to switch a field options in a factbox

    Maybe remove the condition so it would show the sum for each line

  • Manuel Lozada Profile Picture
    Manuel Lozada 465 on at
    RE: procedure to switch a field options in a factbox

    Hi Muaaz

    something like this

    thank for help me, I am beginner AL.

    field("Total Cost"; TotalCostPlanningLine)

               {

                   ApplicationArea = Basic, Suite;

                   Caption = 'Total Budget Cost';

                   ToolTip = 'Show total Budget Cost for current job planning lines.';

                   Visible = true;

                   Editable = false;

               }

               field("Line Amount"; TotalBudgetLineAmount)

               {

                   ApplicationArea = Basic, Suite;

                   Caption = 'Total Budget Billable';

                   ToolTip = 'Show total amount for current job planning lines.';

                   Visible = true;

                   Editable = false;

               }

               field("Net Margin"; TotalNetMargin)

               {

                   ApplicationArea = Basic, Suite;

                   Caption = 'Total Net Margin';

                   ToolTip = 'Show Net Margin for current job planning lines.';

                   Visible = true;

                   Editable = false;

                   AutoFormatType = 10;

                   AutoFormatExpression = '<precision, 2:2><standard format,0>%';

               }

               field(LineBillableAmount; TotalBillableLineAmount)

               {

                   ApplicationArea = Basic, Suite;

                   Caption = 'Total Real Billable Amount';

                   ToolTip = 'Show total amount for current job planning lines.';

                   Visible = true;

                   Editable = false;

               }

    field("Line Type";Rec."Line Type")

               {

                   ApplicationArea = Basic, Suite;

                   Visible = true;

                   Editable = false;

                   trigger OnValidate() // after get a record sum totals

              begin

              if rec."Line Type" = Rec."Line Type"::Budget then begin

               Rec.CalcSums("Total Cost");

               Rec.CalcSums("Line Amount");

               Rec.CalcSums("Net Margin");

               //Rec.CalcSums("Invoiced Amount (LCY)");

               TotalCostPlanningLine := Rec."Total Cost";

               TotalBudgetLineAmount := Rec."Line Amount";

               TotalNetMargin := Rec."Net Margin";

           end;

       end;

               }

           }

       }

       trigger OnInit() //initialize the page equal 0

       begin

           TotalBudgetLineAmount := 0;

           TotalBillableLineAmount := 0;

           TotalNetMargin := 0;

           TotalCostPlanningLine := 0;

       end;

       trigger OnAfterGetCurrRecord() // after get a record sum totals

       begin

           if rec."Line Type" = Rec."Line Type"::Budget then begin

               Rec.CalcSums("Total Cost");

               Rec.CalcSums("Line Amount");

               Rec.CalcSums("Net Margin");

               //Rec.CalcSums("Invoiced Amount (LCY)");

               TotalCostPlanningLine := Rec."Total Cost";

               TotalBudgetLineAmount := Rec."Line Amount";

               TotalNetMargin := Rec."Net Margin";

           end;

       end;

       var //Globals variables

           TotalBudgetLineAmount: Decimal;

           TotalBillableLineAmount: Decimal;

           //TotalUnitPrice: Decimal;

           TotalCostPlanningLine: Decimal;

           TotalNetMargin: Decimal;

  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: procedure to switch a field options in a factbox

    Can you show me how did you wrote it?

  • Manuel Lozada Profile Picture
    Manuel Lozada 465 on at
    RE: procedure to switch a field options in a factbox

    Hi Muaaz,

    I did, but still not working.

    Thank you

  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: procedure to switch a field options in a factbox

    I think you should call this

    if rec."Line Type" = Rec."Line Type"::Budget then begin

               Rec.CalcSums("Total Cost");

               Rec.CalcSums("Line Amount");

               Rec.CalcSums("Net Margin");

               //Rec.CalcSums("Invoiced Amount (LCY)");

               TotalCostPlanningLine := Rec."Total Cost";

               TotalBudgetLineAmount := Rec."Line Amount";

               TotalNetMargin := Rec."Net Margin";

    onValidate of the Line type

  • Manuel Lozada Profile Picture
    Manuel Lozada 465 on at
    RE: procedure to switch a field options in a factbox

    Hi Muaaz,

    I try every time that I change or switch the status in a line (Budget, billable, and Both budget and billable) change the totals in my factbox.

    Thank You

  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: procedure to switch a field options in a factbox

    Can you explain more about what you want to do?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans