Skip to main content

Notifications

Announcements

No record found.

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

procedure to switch a field options in a factbox

(0) ShareShare
ReportReport
Posted on by 355

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;
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 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 29 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 355 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 29 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 355 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 29 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 355 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 29 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans