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.