ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[US][Report][10135][Item Sales Statistics] Add integration event OnBeforePrintOnlyIfSalesCheck (Item Variant) in the OnAfterGetRecord trigger, before the PrintOnlyIfSales skip check

Open mavohra opened this issue 4 months ago • 4 comments

Why do you need this change?

Same rationale as the Item-level companion request #30377 , scoped to Breakdown-By-Variant mode: the Item Variant OnAfterGetRecord trigger has an identical CalcFields + PrintOnlyIfSales skip pattern on Item."Sales (Qty.)", hit whenever "Breakdown By Variant" is enabled on the request page. PrintOnlyIfSales is a private global with no accessible getter. It's unreachable from every kind of extension trigger.

Net effect: when "Only Items with Sales" and "Breakdown By Variant" are both checked, a variant our own alternate-UOM calculation shows as having real sales can be silently skipped before our extension trigger runs, and a variant we'd consider zero-sales can still print. A single event exposing the already-computed skip decision, raised after CalcFields and before CurrReport.Skip(), would let us fold our own figures into the one decision the user sees, at the variant level as well as the item level.

Describe the request

 dataitem("Item Variant"; "Item Variant")
  {
                DataItemLink = "Item No." = field("No.");
                DataItemTableView = sorting("Item No.", Code);
                column(Item_Variant_Code; Code)
                {
                }
...

   trigger OnAfterGetRecord()
   begin
       if BlankVariant then begin
           Code := '';
           "Item No." := '';
           Description := 'Blank Variant';
           "Description 2" := '';
           BlankVariant := false;
       end;

       Item.SetRange("Variant Filter", Code);
       Item.CalcFields("Sales (Qty.)", "Sales (LCY)", "COGS (LCY)");
       SkipRecord := (Item."Sales (Qty.)" = 0) and PrintOnlyIfSales;
       OnItemVariantOnAfterGetRecordOnBeforePrintOnlyIfSalesCheck(Item, Rec, PrintOnlyIfSales, SkipRecord);
       if SkipRecord then
           CurrReport.Skip();
       Profit := Item."Sales (LCY)" - Item."COGS (LCY)";
    ...
end;

...

}

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnItemVariantOnAfterGetRecordOnBeforePrintOnlyIfSalesCheck(var Item: Record Item; ItemVariant: Record "Item Variant"; PrintOnlyIfSales: Boolean; var SkipRecord: Boolean)
begin
end;

Alternatives evaluated:*

  • Reading PrintOnlyIfSales from a request-page control extension's OnAfterValidate, confirmed by the compiler that the variable is inaccessible from every kind of extension trigger, not just dataset ones.
  • Recomputing the entire skip/Profit/ItemProfitPct block ourselves inside a modify("Item Variant") { trigger OnBeforeAfterGetRecord }, not viable even with access, because that trigger runs before the base's own CalcFields, so Item."Sales (Qty.)" isn't populated yet at that point. Internal work item: AB#644154

mavohra avatar Jul 24 '26 14:07 mavohra

Hi @mavohra,

Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.

📚 Extensibility Guidelines

Missing Information:

  • Performance considerations: Describe the expected execution frequency and performance impact of this IsHandled event request.
  • Data sensitivity review: Confirm whether any sensitive data would be exposed by the proposed event parameters and why the exposure is safe.
  • Multi-extension interaction considerations: Explain possible conflicts between multiple subscribers and how those conflicts should be mitigated.

Please update the issue with the missing details. We'll automatically re-analyze once updated.

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Jul 24 '26 19:07 github-actions[bot]

Performance considerations

The event fires where Item Variant's OnAfterGetRecord already fires today: once per Item Variant row processed, and only when "Breakdown By Variant" is checked on the request page — it's not on the default codepath at all, so unchecked reports (the common case) see zero added invocations. When variant breakdown is enabled, this is strictly the existing per-variant iteration with one extra event call appended after the CalcFields that already runs on every row

Data sensitivity review

  • Item — same as #30377: already fully readable via the existing Item.OnAfterGetRecord trigger with the same CalcFields'd fields populated, so no new exposure.
  • ItemVariant (Record "Item Variant") — standard item master data (Code, Item No., Description) that's already readable through numerous existing published events on the Item Variant table/page; nothing here is new surface area.
  • PrintOnlyIfSales — the same request-page "Only Items with Sales" checkbox value described in #30377: a UI filter flag the user sets themselves, not sensitive business data.
  • SkipRecord — transient, non-persisted local boolean scoped to this report run only.

No sensitive data is introduced beyond what's already reachable from existing standard events on this report/table pair.

Multi-extension interaction

Same var Boolean override pattern as #30377 (and the same pattern already used pervasively for IsHandled/skip-style events in the base app): if multiple subscribers set SkipRecord, the last write wins. This is a general characteristic of any shared mutable var parameter, not unique to this event, and Microsoft already accepts this risk profile for the many existing events of this shape. A conservative subscriber can mitigate by only flipping SkipRecord in the direction its own business logic requires rather than unconditionally overwriting a value another extension may have set for its own valid reason.

Happy to adjust naming/placement if there's a preferred convention, and note that #30377 and this one are intended to ship together as a matched pair (item-level and variant-level).

mavohra avatar Jul 27 '26 09:07 mavohra

✅ Analysis complete - ready for further processing


Implementation:

Add a new integration event in the Item Variant OnAfterGetRecord() trigger of report 10135 Item Sales Statistics after Item.CalcFields("Sales (Qty.)", "Sales (LCY)", "COGS (LCY)") and before the CurrReport.Skip() check.

Location in OnAfterGetRecord() trigger:

Item.SetRange("Variant Filter", Code);
Item.CalcFields("Sales (Qty.)", "Sales (LCY)", "COGS (LCY)");
SkipRecord := (Item."Sales (Qty.)" = 0) and PrintOnlyIfSales;
OnItemVariantOnAfterGetRecordOnBeforePrintOnlyIfSalesCheck(Item, "Item Variant", PrintOnlyIfSales, SkipRecord);
if SkipRecord then
    CurrReport.Skip();
Profit := Item."Sales (LCY)" - Item."COGS (LCY)";

Event Publisher (add at the end of the codeunit with other events):

[IntegrationEvent(false, false)]
local procedure OnItemVariantOnAfterGetRecordOnBeforePrintOnlyIfSalesCheck(var Item: Record Item; ItemVariant: Record "Item Variant"; PrintOnlyIfSales: Boolean; var SkipRecord: Boolean)
begin
end;

File: ItemSalesStatistics.Report.al

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Jul 27 '26 13:07 github-actions[bot]

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

AleksandricMarko avatar Sep 01 '26 11:09 AleksandricMarko