Skip to content

[Event Request] codeunit 1400 DocumentNoVisibility procedure ForceShowNoSeriesForDocNo event OnBeforeForceShowNoSeriesForDocNo #29898

@janpopr

Description

@janpopr

Why do you need this change?

Add OnBeforeForceShowNoSeriesForDocNo event in DocumentNoVisibility codeunit

The procedure ForceShowNoSeriesForDocNo in codeunit DocumentNoVisibility contains fixed logic that determines whether the document number field should be visible.

Currently, there is no extensibility point that allows:

Overriding the visibility decision
Injecting custom logic for specific No. Series scenarios
Supporting extension-based customization

This creates a functional gap in scenarios where numbering behavior is influenced by custom logic or external systems.

Alternatives evaluated
No existing event is available in this procedure or surrounding logic
Extending via page logic is not sufficient, as the visibility decision is encapsulated in the codeunit
Replacing standard logic is not feasible without duplicating base functionality
A non-IsHandled event would not be sufficient, as full override of the decision is required
Proposed publisher location
Object: Codeunit 1400 – DocumentNoVisibility
Procedure: ForceShowNoSeriesForDocNo
Placement rationale:
The event is placed at the beginning of the procedure to allow full override while keeping the remaining logic intact and minimal.

Justification for using IsHandled

A full override of the base logic is required.

A standard event without IsHandled would not allow replacing the visibility decision, only reacting to it. In this case, extensions must be able to completely control the outcome.

Although the IsHandled pattern has known drawbacks, it is justified here because:

The method encapsulates a decision (Boolean return)
There is no smaller extensibility point inside the logic
Partial extension is not sufficient
Performance & data considerations
The method is lightweight and executed per UI evaluation
No large datasets or loops are involved
The event introduces negligible overhead
No sensitive data is exposed (only NoSeriesCode and Boolean result)
Multi-extension interaction
The IsHandled pattern introduces a risk where only one extension effectively controls the result
This is acceptable because:
The logic represents a single final decision
Conflicts can be managed by extension design (priority, coordination)

This limitation is inherent to the IsHandled pattern and considered acceptable for this scenario.

Additional context

The IsHandled pattern should be used sparingly and only when necessary, as it can negatively impact maintainability and multi-extension scenarios.

In this case, however, it is the only viable approach to allow full control over the logic.

Use case example

In our solution, we have implemented custom functionality that controls access permissions to specific No. Series.

We maintain a unified approach where the accessibility of individual No. Series is evaluated centrally based on our custom permission model.

The procedure ForceShowNoSeriesForDocNo represents a key decision point, where it is necessary to determine whether a given No. Series should be available to the user.

Currently, this decision cannot be influenced by our custom logic.

By introducing the proposed event, we would be able to:

Apply our centralized permission logic consistently
Dynamically control visibility of document numbers based on user-specific access to No. Series
Ensure that the behavior aligns with our security model without duplicating or replacing standard logic

This results in a clean, maintainable, and reusable solution that integrates seamlessly with the standard application.

Describe the request

codeunit 1400 DocumentNoVisibility Line no. 573

procedure ForceShowNoSeriesForDocNo(NoSeriesCode: Code[20]) DocNoVisible: Boolean
var
NoSeries: Record "No. Series";
NoSeriesRelationship: Record "No. Series Relationship";
NoSeriesBatch: Codeunit "No. Series - Batch";
SeriesDate: Date;
IsHandled: Boolean;
begin
OnBeforeForceShowNoSeriesForDocNo(NoSeriesCode, DocNoVisible, IsHandled);
if IsHandled then
exit(DocNoVisible);

if not NoSeries.Get(NoSeriesCode) then
    exit(true);

SeriesDate := WorkDate();
NoSeriesRelationship.SetRange(Code, NoSeriesCode);
if not NoSeriesRelationship.IsEmpty() then
    exit(true);

if NoSeries."Manual Nos." or (NoSeries."Default Nos." = false) then
    exit(true);

exit(NoSeriesBatch.GetNextNo(NoSeriesCode, SeriesDate, true) = '');

end;

[IntegrationEvent(false, false)]
local procedure OnBeforeForceShowNoSeriesForDocNo(
NoSeriesCode: Code[20];
var DocNoVisible: Boolean;
var IsHandled: Boolean)
begin
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions