web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

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

CurrPage.SetSelectionFilter with OnAfterGetCurrRecord

(2) ShareShare
ReportReport
Posted on by 7
Problem Statement:

We are encountering significant instability and inconsistency when attempting to display a real-time sum of quantities from user-selected Sales Lines within a FactBox in Dynamics 365 Business Central. Our goal is for the FactBox to automatically update as users select multiple lines  on the Sales Order Subform, without requiring an explicit action button or relying on FlowFields.

Current Implementation Approach:

Our solution involves a custom FactBox page (Sales Line Qty FactBox) that uses a temporary SourceTable = "Sales Line" to receive a filtered set of records. The calculation logic is placed in a procedure (SetTotalSelectedQty) within the FactBox, which is called from the OnAfterGetCurrRecord trigger of the Sales Order Subform page extension.

Code Snippets:

1. FactBox Page (Sales Line Qty FactBox - Page 50100)

2. Sales Order Subform Page Extension (PageExtension 50101 extends "Sales Order Subform")

Observed Problem Behavior:

When a user selects multiple lines on the Sales Order Subform grid using Ctrl+Click or Shift+Click (especially for non-contiguous selections), the FactBox's displayed total often:


  • Does not update immediately.

  • Updates with an incorrect value, frequently showing only the quantity of the last clicked/focused line, rather than the sum of all visually selected lines.

  • The behavior is inconsistent; sometimes it seems to capture the full selection, other times it fails. This is particularly noticeable when comparing mouse-driven selections to keyboard-driven (Shift + Arrow) selections (though we wish to avoid this distinction in the solution).


  •  

Why this approach is desired:


  • User Experience: We aim for a seamless, real-time feedback loop for the user without requiring an extra click (an action button) to update the total.

  • Avoidance of FlowFields: FlowFields aggregate data based on table filters, not interactive user selections, making them unsuitable for this specific "selected rows" requirement.


  •  

Our Core Question to the Community:

Given that OnAfterGetCurrRecord combined with SetSelectionFilter exhibits unstable behavior for dynamic multi-row selections (especially with mouse interaction), and without using explicit actions or FlowFields, is there a reliable and robust AL-only pattern to achieve a real-time FactBox sum of dynamically selected grid rows in Business Central?

We are seeking insights or alternative approaches that might overcome this apparent platform limitation in the AL eventing model for UI selections.

 

I have the same question (0)
  • Suggested answer
    RockwithNav Profile Picture
    8,370 Super User 2025 Season 2 on at
    CurrPage.SetSelectionFilter with OnAfterGetCurrRecord
    Once the Record on the Mater Page will change or you will click next then it will update, seems in that one unique case of yours the trigger is not getting triggered, you may need to change the approach.
  • Gerardo Rentería García Profile Picture
    23,574 Most Valuable Professional on at
    CurrPage.SetSelectionFilter with OnAfterGetCurrRecord
  • Suggested answer
    YUN ZHU Profile Picture
    92,770 Super User 2025 Season 2 on at
    CurrPage.SetSelectionFilter with OnAfterGetCurrRecord
    You need to change your solution, hopefully the information below can give you some hints.
    Dynamics 365 Business Central: Can we add Item Attributes Factbox (9110, ListPart) to Sales Order (42, Document) page??? Yes, But……
     
    Thanks.
    ZHU
  • Suggested answer
    YUN ZHU Profile Picture
    92,770 Super User 2025 Season 2 on at
    CurrPage.SetSelectionFilter with OnAfterGetCurrRecord
    PS:
    Dynamics 365 Business Central: How to add Total Quantity, Number of Lines to the Sales Order List page – Customization
    Dynamics 365 Business Central: How to add new fields to Total Area on the Document Subform page (View Total Quantity, Number of Lines on the Sales Order)
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,089 Super User 2025 Season 2 on at
    CurrPage.SetSelectionFilter with OnAfterGetCurrRecord
    You're absolutely right — relying on OnAfterGetCurrRecord and CurrPage.SetSelectionFilter to dynamically track multi-row selections (especially with mouse interactions) is unreliable in current Business Central behavior. This is due to platform limitations where selection events are not fully committed or detectable at the time of OnAfterGetCurrRecord, especially for Ctrl+Click or Shift+Click.
     
    ✅ Why it behaves inconsistently:
     
    SetSelectionFilter only catches the active selection, not the full range of visually selected rows.
     
    OnAfterGetCurrRecord fires per record in a list but is not triggered by selection changes, so you're reacting to focus, not selection.
     
    BC doesn't expose a true "selection changed" event for page parts.
     
     
     
    ---
     
    🔧 Suggested Workaround (Minimal Disruption):
     
    Instead of real-time updates, trigger the total on user interaction with a custom action (e.g. "Update Selected Total").
     
    Add a Page Action on the Subform:
     
    action(UpdateSelectedQty)
    {
        Caption = 'Update Selected Qty';
        Image = Sum;
        ApplicationArea = All;
        trigger OnAction()
        var
            SelectedSalesLines: Record "Sales Line";
            TotalQty: Decimal;
        begin
            CurrPage.SetSelectionFilter(SelectedSalesLines);
            if SelectedSalesLines.FindSet() then
                repeat
                    TotalQty += SelectedSalesLines.Quantity;
                until SelectedSalesLines.Next() = 0;
     
            // Now call a global method or a single instance Codeunit to update FactBox field via Event or a table field
            MyFactBoxHelper.SetTotalQty(TotalQty);
        end;
    }
     
    > This adds one-click interaction to update the FactBox — stable, clear and user-controlled.
     
     
     
     
    ---
     
    🔄 More Dynamic (Optional):
     
    If you insist on avoiding actions:
     
    Use a single instance codeunit or temporary table to act as a shared state container between subform and FactBox.
     
    But you’ll still face race conditions due to timing of focus and selection updates.
     
    In BC's current model, real-time multi-selection tracking without a button is not fully supported.
     
     
     
    ---
     
    🧠 Future Suggestion:
     
    Consider submitting a suggestion on the BC Ideas Portal asking for:
     
    > A "SelectionChanged" trigger on list pages that would allow FactBox or surrounding UI to respond.
     
     
     
     
    ---
     
    ✅ Conclusion:
     
    At the moment, adding an "Update Total" button is the most reliable and user-friendly method. Real-time selection tracking for FactBox without FlowFields or buttons is not currently feasible with stability.
     
    Let me know if you'd like a sample repo for the shared state handling!
     
    ✅ Mark this answer as verified if it helps you.
     
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,330

#2
Sumit Singh Profile Picture

Sumit Singh 2,738

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,546

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans