bcquality/microsoft/knowledge/events/prefer-reusing-or-extending-existing-events.md
Jesper Schulz-Wedde 2b5550c346
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Improve partner onboarding and documentation navigation (#174)
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:31:03 +02:00

1.8 KiB

bc-version domain keywords technologies countries application-area
all
events
event-reuse
duplication
consecutive-events
extension-point
onbefore
integration-event
maintainability
al
w1
all

Prefer reusing or extending existing events

Description

Before adding a publisher, check whether an event already fires at that point in the code. Two related smells signal that you should reuse or extend instead of adding one. The first is a brand-new event placed directly next to an existing one — two consecutive event raises with no logic between them, which gives subscribers two seams where one belongs. The second is a near-duplicate event that differs from an existing one only by an extra parameter. Both bloat the publisher surface and leave subscribers unsure which event to pick. Prefer subscribing to the existing event, or extending it by appending the parameter you need, over introducing a parallel one.

Best Practice

When the data you need is already exposed at an existing event, subscribe to it. When the event lacks a parameter, extend that event by appending the parameter at the end — one publisher, one raise — rather than adding a second event beside it.

See sample: prefer-reusing-or-extending-existing-events.good.al.

Anti Pattern

Adding a second event raise immediately after an existing one, or creating OnBeforeProcessOrderWithCustomer next to OnBeforeProcessOrder just to add a single parameter. Detection: two consecutive OnBefore…/OnAfter… raises with no logic between them, or near-duplicate event names differing only by a parameter-describing suffix.

See sample: prefer-reusing-or-extending-existing-events.bad.al.