BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Extensibility Request] Add OnBeforeRestrictGenJournalLineAfterModify event to RestrictGenJournalLineAfterModify in codeunit 1550 "Record Restriction Mgt."

Open manichoy opened this issue 3 months ago • 9 comments

Describe the issue

Please add an integration event before the call to RestrictGenJournalLine(Rec) in procedure RestrictGenJournalLineAfterModify of Codeunit 1550 "Record Restriction Mgt."

Some extensions need to modify General Journal Lines programmatically after posting preparation or during custom processing.

When a General Journal Line is modified, the standard Record Restriction logic is automatically executed through RestrictGenJournalLineAfterModify. Currently there is no extensibility point available to:

Skip the restriction logic under specific business scenarios. Override the standard restriction behaviour. Execute custom validation before the restriction is applied.

Without an event, partners must modify data in ways that are difficult to control and cannot cleanly integrate with the standard restriction framework.

Expected behavior

An extensibility event should be available before RestrictGenJournalLine(Rec) is executed, allowing extensions to intercept the standard restriction process.

The event should:

Provide access to both Gen. Journal Line and xGen. Journal Line records. Expose an IsHandled parameter so extensions can suppress the standard call to RestrictGenJournalLine(Rec) when required. Allow partners to implement alternative restriction logic or business-specific validation. Preserve existing behavior when no subscribers are implemented.

Steps to reproduce

Add a new Integration Event named: OnBeforeRestrictGenJournalLineAfterModify in the following procedure:

[EventSubscriber(ObjectType::Table, Database::"Gen. Journal Line", 'OnAfterModifyEvent', '', false, false)]
procedure RestrictGenJournalLineAfterModify(var Rec: Record "Gen. Journal Line"; var xRec: Record "Gen. Journal Line"; RunTrigger: Boolean)
begin
    if Format(Rec) = Format(xRec) then
        exit;

    RestrictGenJournalLine(Rec);
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeRestrictGenJournalLineAfterModify(
    var GenJournalLine: Record "Gen. Journal Line";
    xGenJournalLine: Record "Gen. Journal Line";
    var IsHandled: Boolean)
begin
end;

Resulting Code

[EventSubscriber(ObjectType::Table, Database::"Gen. Journal Line", 'OnAfterModifyEvent', '', false, false)]
procedure RestrictGenJournalLineAfterModify(var Rec: Record "Gen. Journal Line"; var xRec: Record "Gen. Journal Line"; RunTrigger: Boolean)
var
    IsHandled: Boolean;
begin
    if Format(Rec) = Format(xRec) then
        exit;

    OnBeforeRestrictGenJournalLineAfterModify(Rec, xRec, IsHandled);

    if IsHandled then
        exit;

    RestrictGenJournalLine(Rec);
end;
`

Additional context

I will provide a fix for a bug

  • [x] I will provide a fix for a bug

manichoy avatar Aug 21 '26 00:08 manichoy

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

github-actions[bot] avatar Aug 21 '26 00:08 github-actions[bot]

Hi @manichoy,

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:

  • Alternatives evaluated: Explain which existing events or extensibility patterns were considered and why they do not meet this scenario.
  • Justification for IsHandled: Explain why a regular event or another design is insufficient, and why an IsHandled pattern is specifically required.
  • Performance considerations: Describe the expected execution frequency and any performance impact considerations for adding this event.
  • Data sensitivity review: Confirm whether exposing Gen. Journal Line and xGen. Journal Line in this event introduces any sensitive data concerns.
  • Multi-extension interaction: Explain how the design should behave if multiple extensions subscribe and use IsHandled.

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] Is the triage result incorrect? Reply with /not-accurate and briefly explain what was wrong. Your feedback improves future responses.

github-actions[bot] avatar Aug 29 '26 19:08 github-actions[bot]

  1. Alternatives evaluated

I evaluated the existing extensibility points around General Journal processing and Record Restriction handling.

The following alternatives were considered:

  • Subscribing to existing Gen. Journal Line table events before or after the modification.
  • Subscribing to events in posting codeunits and attempting to avoid the modification that triggers the restriction logic.
  • Implementing custom logic after the restriction has already been applied.

None of these alternatives provide a mechanism to intercept the call to RestrictGenJournalLine(Rec) itself.

The issue is that RestrictGenJournalLineAfterModify() is an internal subscriber that automatically executes after a Gen. Journal Line is modified. Once execution reaches RestrictGenJournalLine(Rec), extensions have no opportunity to:

  • Prevent the restriction from being created.
  • Replace the restriction behavior with an alternative implementation.
  • Execute custom validation before the restriction logic is evaluated.

As a result, existing events allow reacting to the modification but not controlling the Record Restriction decision point itself.

  1. Justification for IsHandled

An IsHandled pattern is required because the requested scenario is not additive in nature. The primary goal of this request is not to customize the restriction logic, but to allow controlled suppression of the standard behavior when an extension implements its own restriction handling mechanism. A regular event cannot achieve this requirement.

A regular integration event would allow extensions to execute additional logic before the restriction is applied, but it would not allow them to prevent the standard call to:

RestrictGenJournalLine(Rec);

Certain solutions need to completely bypass the standard restriction logic under controlled business scenarios. Examples include:

  • Custom posting frameworks.
  • Batch journal preparation processes.
  • Temporary transformation of journal lines during automated processing.
  • Alternative restriction implementations maintained by partner extensions.

In these scenarios the extension must be able to suppress the standard behavior and take full responsibility for restriction handling. This is consistent with other platform extensibility points where a single decision point must be overridable.

Without IsHandled, the event would only support pre-processing and would not solve the primary extensibility gap.

  1. Performance considerations

The event would execute only when:

  • A Gen. Journal Line record is modified.
  • The record content has changed (Format(Rec) <> Format(xRec)).

The proposed implementation adds:

OnBeforeRestrictGenJournalLineAfterModify(...);

before an already existing operation.

The performance impact is expected to be negligible because:

  • Integration event invocation is lightweight when there are no subscribers.
  • The event is added directly before the existing restriction logic and does not introduce additional database operations.
  • Extensions that subscribe to the event are responsible for the efficiency of their own implementations.

Therefore the proposed event should not materially change the performance characteristics of the standard flow.

  1. Data sensitivity review

No additional data sensitivity concerns are introduced.

The event exposes:

var GenJournalLine: Record "Gen. Journal Line";
xGenJournalLine: Record "Gen. Journal Line";

These records are already available to extension developers through existing table events and standard AL extensibility patterns related to General Journal processing.

The proposal does not expose:

  • New fields.
  • Additional tables.
  • Cross-company data.
  • System-level security information.

The event simply provides access to the same records already involved in the current execution context.

  1. Multi-extension interaction

The proposed event follows the standard Business Central IsHandled pattern.

Expected behavior:

  • All subscribers are invoked according to the existing event subscriber execution model.
  • Any subscriber may set IsHandled := true.
  • When IsHandled is true, the standard call to RestrictGenJournalLine(Rec) is skipped.
  • Extensions that choose to set IsHandled assume responsibility for ensuring that the resulting behavior remains valid for their business scenario.

This behavior is consistent with existing OnBefore* events across Business Central where an extension intentionally overrides standard functionality.

As with other IsHandled events, solution publishers should be aware that multiple extensions may subscribe to the same event, and subscribers should be designed accordingly.

manichoy avatar Aug 30 '26 00:08 manichoy

Hi @manichoy,

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:

  • xGenJournalLine necessity: Confirm that access to the previous-record values (xGenJournalLine/xRec) is specifically required for your scenario and explain how those values will be used in this event context.
  • Bypass safety for IsHandled: Explain how your extension will safely replace or handle the record restriction logic that would be bypassed when IsHandled := true, including how business validation and integrity will be preserved.

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] Is the triage result incorrect? Reply with /not-accurate and briefly explain what was wrong. Your feedback improves future responses.

github-actions[bot] avatar Aug 30 '26 01:08 github-actions[bot]

  1. xGenJournalLine necessity

Yes, access to both GenJournalLine and xGenJournalLine is required.

The event is intended to execute in the same context as the current implementation of RestrictGenJournalLineAfterModify(), where the standard logic already evaluates changes between Rec and xRec.

A subscriber may need to compare the previous and current values to determine whether record restriction logic should be applied. Examples include:

Identifying which fields were modified. Determining whether a modification was made only for internal processing purposes. Applying alternative restriction logic only when specific business-critical fields have changed. Preventing unnecessary restriction processing when certain controlled updates occur.

Without access to xGenJournalLine, subscribers would need to re-read historical state from other sources or maintain their own tracking mechanisms, which would be less reliable and less efficient.

Providing both records follows the standard Business Central pattern for modification-related events and enables extensions to make the same change-based decisions that the base application can make.

  1. Bypass safety for IsHandled

The intention is not to disable record protection indiscriminately, but to allow controlled replacement of the standard restriction logic in specific extension scenarios.

When an extension sets:

IsHandled := true;

the extension assumes responsibility for handling the restriction decision and preserving business integrity.

For example, an extension may:

Execute equivalent restriction checks through a custom implementation. Apply restrictions only after a multi-step business process completes. Defer restriction creation until all automated updates have finished. Implement stricter validation rules than the standard behavior.

The extension would still perform validation before allowing modifications to proceed and would ensure that records cannot be unintentionally changed once they reach a protected business state.

The proposed event does not reduce the safety of the base application because:

Existing behavior remains unchanged unless an extension explicitly subscribes and sets IsHandled := true. Only trusted installed extensions can bypass the standard call. The extension becomes fully responsible for maintaining the required business controls. This follows the same responsibility model already used by numerous existing OnBefore... events that expose IsHandled in Business Central.

The goal is to provide an extensibility point for advanced scenarios where the standard restriction mechanism cannot be applied directly, while preserving the default behavior for all other implementations.

manichoy avatar Aug 30 '26 03:08 manichoy

Hi @manichoy,

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:

  • Bypass safety confirmation: Please confirm that you understand IsHandled := true would skip the standard RestrictGenJournalLine(Rec) validation/restriction path, and that any subscribing extension will fully replace that skipped logic with equivalent or otherwise safe handling.

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] Is the triage result incorrect? Reply with /not-accurate and briefly explain what was wrong. Your feedback improves future responses.

github-actions[bot] avatar Aug 30 '26 07:08 github-actions[bot]

We understand that setting IsHandled := true would completely bypass the standard RestrictGenJournalLine(Rec) validation and restriction logic. Our intention is not to disable those restrictions without replacement. Any extension subscribing to this event and setting IsHandled := true would be responsible for implementing equivalent or otherwise appropriate validation logic to ensure safe handling of the journal line. We acknowledge that the subscriber assumes full responsibility for maintaining the integrity and safety guarantees normally provided by the base application logic when IsHandled := true is used.

manichoy avatar Aug 31 '26 22:08 manichoy

✅ Analysis complete - ready for further processing


Implementation:

Add a new integration event in RestrictGenJournalLineAfterModify before RestrictGenJournalLine(Rec) so extensions can inspect the current and previous Gen. Journal Line records and optionally suppress the standard restriction logic with IsHandled.

Location in RestrictGenJournalLineAfterModify procedure:

[EventSubscriber(ObjectType::Table, Database::"Gen. Journal Line", 'OnAfterModifyEvent', '', false, false)]
procedure RestrictGenJournalLineAfterModify(var Rec: Record "Gen. Journal Line"; var xRec: Record "Gen. Journal Line"; RunTrigger: Boolean)
var
    IsHandled: Boolean;
begin
    if Format(Rec) = Format(xRec) then
        exit;

    IsHandled := false;
    OnBeforeRestrictGenJournalLineAfterModify(Rec, xRec, IsHandled);
    if IsHandled then
        exit;

    RestrictGenJournalLine(Rec);
end;

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

[IntegrationEvent(false, false)]
local procedure OnBeforeRestrictGenJournalLineAfterModify(var GenJournalLine: Record "Gen. Journal Line"; xGenJournalLine: Record "Gen. Journal Line"; var IsHandled: Boolean)
begin
end;

File: RecordRestrictionMgt.Codeunit.al

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

[!TIP] Is the triage result incorrect? Reply with /not-accurate and briefly explain what was wrong. Your feedback improves future responses.

github-actions[bot] avatar Sep 01 '26 01:09 github-actions[bot]

Hi, just checking if there are any updates on this PR or if any further information/action is required from my side. Thanks!

manichoy avatar Nov 26 '26 12:11 manichoy