ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[W1][Report][840][Suggest Worksheet Lines] OnAfterGetRecord Job Planning Line - add IsHandled

Open MortegaITB opened this issue 3 months ago • 1 comments

Why do you need this change?

Report 840 "Suggest Worksheet Lines" generates cash flow lines from Job Planning Line unconditionally for every billable line, with no way to exclude lines belonging to specific projects (e.g. projects with Status = Completed).

The dataitem "Job Planning Line" already fires an event right before line generation:

trigger OnAfterGetRecord()
begin
    Window.Update(2, JobsMsg);
    Window.Update(3, "Job No.");

    if not ("Line Type" in ["Line Type"::Billable, "Line Type"::"Both Budget and Billable"]) then
        exit;

    OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine("Job Planning Line");
    InsertCFLineForJobPlanningLine();
end;

However, OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine has no way to signal back to the caller, so a subscriber can react to the record but cannot prevent the subsequent, unconditional call to InsertCFLineForJobPlanningLine(). Today there is no supported way to skip cash flow line generation (and its side effect of updating and persisting the Job Planning Line record via UpdatePlannedDueDate() / Modify()) for a specific line without a workaround.

Alternatives evaluated:

  • Filtering "Job Planning Line" via SetFilter on "Job No." at OnPreDataItem (e.g. <>proj1&<>proj2&...): Rejected. With, for example, 500 completed projects out of 10,000 total planning lines, the exclusion list would have to enumerate up to 500 project numbers in a single filter string. AL filter strings have a maximum length, so this fails or truncates once the excluded set grows past a relatively small number of values — it doesn't scale with real data volumes.
  • Post-processing and deleting already-inserted lines in Cash Flow Worksheet Line: Works around the filter-length limit, but performs redundant work (lines are calculated and inserted, then removed) and risks temporary inconsistent state.
  • Duplicating the report's logic in a custom extension: Maintenance liability with every BC update. Rejected.
  • Adding a brand-new event publisher instead of extending the existing one: Considered, but rejected — OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine already fires at exactly the right point (immediately before InsertCFLineForJobPlanningLine()), so a second, near-duplicate event would be redundant.

Why a Skip parameter, not a generic IsHandled: a standard (non-skip) OnBefore/OnAfter event can't solve this, since the requirement is to conditionally prevent both the cash flow line insertion and the record's own Modify() side effect from happening at all — some boolean signal back to the caller is unavoidable. Per Types of events for extensibility, a generic IsHandled parameter is classified as a Handled event (Low Value), because by contract only one subscriber can effectively drive the outcome and it doesn't scale across multiple subscribers. This request instead uses the higher-quality OnSkip pattern (Medium Value), with a specifically named parameter (SkipCFLineForJobPlanningLine) that documents exactly what is skipped and lets independent subscribers each contribute to the decision without conflicting.

Benefit: enables partners/customers to exclude specific Job Planning Line records (e.g. belonging to completed projects) from cash flow forecasting without workarounds, filter-length limits, or duplicated report logic — at O(1) cost per already-processed line, with no new event and no additional recordset iteration.

Describe the request

Add a new var SkipCFLineForJobPlanningLine: Boolean parameter to the existing event publisher OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine in Report 840 "Suggest Worksheet Lines", and use it in "Job Planning Line" - OnAfterGetRecord to skip InsertCFLineForJobPlanningLine() when a subscriber sets it to true. This is a single object, minimal, additive change (one parameter appended to the end of an existing event) — no dependent objects.

Before:

trigger OnAfterGetRecord()
begin
    Window.Update(2, JobsMsg);
    Window.Update(3, "Job No.");

    if not ("Line Type" in ["Line Type"::Billable, "Line Type"::"Both Budget and Billable"]) then
        exit;

    OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine("Job Planning Line");
    InsertCFLineForJobPlanningLine();
end;

[IntegrationEvent(false, false)]
local procedure OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine(JobPlanningLine: Record "Job Planning Line")
begin
end;

After:

trigger OnAfterGetRecord()
var
    SkipCFLineForJobPlanningLine: Boolean;
begin
    Window.Update(2, JobsMsg);
    Window.Update(3, "Job No.");

    if not ("Line Type" in ["Line Type"::Billable, "Line Type"::"Both Budget and Billable"]) then
        exit;

    SkipCFLineForJobPlanningLine := false;
    OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine("Job Planning Line", SkipCFLineForJobPlanningLine);
    if SkipCFLineForJobPlanningLine then
        exit;

    InsertCFLineForJobPlanningLine();
end;

[IntegrationEvent(false, false)]
local procedure OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine(JobPlanningLine: Record "Job Planning Line"; var SkipCFLineForJobPlanningLine: Boolean)
begin
end;

Illustrative subscriber:

[EventSubscriber(ObjectType::Report, Report::"Suggest Worksheet Lines", 'OnJobPlanningLineOnAfterGetRecordOnBeforeInsertCFLineForJobPlanningLine', '', false, false)]
local procedure SkipCFLineForCompletedProjects(JobPlanningLine: Record "Job Planning Line"; var SkipCFLineForJobPlanningLine: Boolean)
var
    Job: Record Job;
begin
    if Job.Get(JobPlanningLine."Job No.") and (Job.Status = Job.Status::Completed) then
        SkipCFLineForJobPlanningLine := true;
end;

Multiple subscribers can each independently set SkipCFLineForJobPlanningLine := true for their own exclusion criteria (e.g. completed projects, on-hold projects) without needing to check whether another subscriber already handled the record — any subscriber setting it to true is sufficient, since the outcome (skip the line) is the same regardless of which criterion triggered it. Worst case with multiple extensions installed, a line is skipped that another extension might have wanted included — this doesn't cause data corruption or inconsistent state. Existing code paths are unaffected: the parameter defaults to false, so InsertCFLineForJobPlanningLine() still executes exactly as before when no subscriber sets it.

Performance & data considerations: No new event and no additional recordset iteration are introduced — the existing event already fires once per "Job Planning Line" record processed by the dataitem. A subscriber's Job.Get("Job No.") is a primary-key lookup, so cost scales linearly with the number of planning lines already being processed, not with the number of excluded projects (e.g. 500 completed out of 10,000 total lines, or larger) — no filter string is ever built or concatenated. No additional sensitive or GDPR-relevant data is exposed; "Job Planning Line" is already present in the existing event signature.

MortegaITB avatar Aug 24 '26 07:08 MortegaITB

Hi @MortegaITB,

Thank you for your extensibility request. Unfortunately, this request cannot be implemented.

Reason: This request cannot be approved. Adding an IsHandled pattern to an existing event is not allowed because it fundamentally changes the event's purpose and contract. Existing subscribers rely on the current behavior, and introducing IsHandled would break them by allowing the base logic to be bypassed — something the original subscribers were never designed to account for.

If you need bypass/handled functionality, please request a NEW separate event with IsHandled instead of modifying the existing one.

[!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 Aug 24 '26 13:08 github-actions[bot]