Skip to main content

Notifications

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

Adding a Control to a Page that Sums a field, using filters on the page

Posted on by 372

Hello,

I am trying to create a control at the bottom of pages like Posted Sales Invoice Lines, that would sum the amount fields, and that amount updates with what filters you apply to the page. Kind of like the controls at the bottom of the payment journal. What would be the proper way to do so? I was able to put the group, and fixed field that is a variable type decimal. But thats as far as I was able to get.

ExampleControl.png

  • Suggested answer
    Esteban Bazan Profile Picture
    Esteban Bazan 10 on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    Setselectionfilter Documentation:

    •Copies the current filters that are set in all filter groups. WHEN you select MORE than one record.

    So, you can't use it. The real problem heres is that Bussines Central doesn't has an event called OnAfterPageUpdate, and we can't us OnAfterGetRecord because BC call it when the user do clic on blanc filter but having other live filters...

    and there is no event for when the filters change.

    complicating it...

    So, if you want copy the filters you can do it, with Var.Copyfilters(rec)

    But when? Using a button ? for that better what Madest said.

  • ChazKimRP Profile Picture
    ChazKimRP 372 on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    Okay. Excuse my ignorance as I’ve only used it to update records the user has highlighted.

    Currpage.setselectionfilter(ItemRec)

    This would filter the ItemRec variable to be whatever the user applied as filter, not just what they have highlighted/selected in the list?

    If this works it will truly be a win to not have to write a bunch of reports for the users.

  • DynamicMax Profile Picture
    DynamicMax 10 on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    The  function currpage.setselectionfilter get back the user filter on a record variable.

    Check the Micrisoft documentation

    docs.microsoft.com/.../setselectionfilter-function

  • ChazKimRP Profile Picture
    ChazKimRP 372 on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    Thank you for the response, however, say they go to the posted sales invoice lines page, and set a filter of location code is <value> or apply a date range. I would want whatever filters they apply to also filter my total field in the group below the repeater. I guess that’s where I am stuck, utilizing the users filters to filter the field.

  • Madest Profile Picture
    Madest 15 on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    Possibly the best solution would be and more powerful:

    On the page, in the OnAfterGetCurrentRecord event, you have to add the following:

    CurrPage.SetSelectionFilter (rSalesInvoices);

    rSalesInvoices.CALCSUMS (Field);

    dAmountSum: = rSalesInvoices.Field;

    With this you add what you select and it is more practical. (You can select everything with the upper left corner)

    I hope it helps.

    Greetings.

  • ChazKimRP Profile Picture
    ChazKimRP 372 on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    I am able to through VS Code Extension deployment to our Test DB. However, I tried what you suggested and could not get it to work. Could you possibly give me a short example on how you would do it, utilizing the filters the user applied to the page?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding a Control to a Page that Sums a field, using filters on the page

    You'll need some devlopment capabilities to do this.

    In the page designer, you can create a new group after the repeater and put a variable based field in.

    You will have to set manually the caption of this field and to calculate the value with code for exemple in the "OnAfterGetRecord" event with a loop summing value under the particular conditions you want.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans