Skip to content

[Bug]: Eventrequest on Codeunit 2682 Data Search Events #8970

Description

@NicoBroenstrup

Describe the issue

We want to extend the Search App using the Sales Responsibility filter,in the same way this is done in pages of the Base App. When a user clicks "Show More", the procedure ShowRecords performs the search again.
At this point, there is no possibility to filter the records based on the "Responsibility Center" field.

Expected behavior

To solve this requirement, we need a new Event in Codeunit 2682 (Data Search Events) - add at the end of this codeunit:

/// <summary>
/// Allows adding additional filters to the RecordRef used to display
/// all search result records (page "Data Search Result Records").
/// This event is raised after the search filters have been applied
/// but before the records are displayed, enabling extensions to add
/// security or business logic filters (e.g. Responsibility Center filtering).
/// </summary>
/// <param name="RecordRef">The filtered RecordRef on which all results will be displayed.</param>
/// <param name="TableSubtype">The table subtype (e.g. Document Type) as an integer.</param>
[IntegrationEvent(false, false)]
procedure OnAfterSetSourceRecRef(var RecordRef: RecordRef; TableSubtype: Integer)
begin
end;

The Event must be raised in Page Data Search Results (Page 2682 "Data Search Result Records") in procedure "SetSourceRecRef":

internal procedureRef(
    var RecRef: RecordRef;
    TableSubtype: Integer;
    SearchString: Text;
    NewPageCaption: Text)
var
    DataSearchInTable: Codeunit "Data Search in Table";
    DataSearchEvents: Codeunit "Data Search Events"; // NEW
    FldRef: FieldRef;
begin
    if RecRef.Number = 0 then
        exit;

    DataSearchInTable.SplitSearchString(SearchString, SearchStrings);
    SearchStrings.Get(1, SearchString);
    DataSearchInTable.GetFieldList(RecRef, FieldList);

    SourceRecRef.Open(RecRef.Number);
    FldRef := SourceRecRef.Field(SourceRecRef.SystemModifiedAtNo);
    SourceRecRef.SetView(StrSubstNo(SetViewLbl, FldRef.Name));

    DataSearchInTable.SetFiltersOnRecRef(SourceRecRef, TableSubtype, SearchString);

    // Raise event to allow additional filtering (e.g. Responsibility Center)
    DataSearchEvents.OnAfterSetSourceRecRef(SourceRecRef, TableSubtype);

    TableCaptionTxt := NewPageCaption;
end;

Steps to reproduce

  1. Use the Data Search feature to search for records of a table that has a
    "Responsibility Center" field (e.g. sales documents).
  2. Click "Show More" to open page 2682 "Data Search Result Records", which calls
    SetSourceRecRef and re-runs the search.
  3. In an extension, try to restrict the displayed results to the user's allowed
    Responsibility Center.
  4. Observe that there is no event on the filtered RecordRef in SetSourceRecRef,
    so the extension cannot apply the additional filter and unrelated records remain
    visible.

Additional context

The Base Application already applies Responsibility Center filtering on its standard
pages. We need the same capability for Data Search results so that users only see
records they are allowed to see.

The requested event is minimal, additive, and backward-compatible: it introduces a
single OnAfter… integration event with a var RecordRef parameter, following the
existing event patterns in the Data Search App. It would let extensions add security
and business-logic filters cleanly at the correct point in the pipeline.

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

Labels

AI-TriageManually trigger or re-trigger an AI triage assessmentApprovedThe issue is approvedIntegrationGitHub request for Integration area

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions