Skip to content

Fix: RecordSelection should not display Media fields#7850

Open
jeffreybulanadi wants to merge 1 commit intomicrosoft:mainfrom
jeffreybulanadi:fix/1198-record-selection-filter-media-fields
Open

Fix: RecordSelection should not display Media fields#7850
jeffreybulanadi wants to merge 1 commit intomicrosoft:mainfrom
jeffreybulanadi:fix/1198-record-selection-filter-media-fields

Conversation

@jeffreybulanadi
Copy link
Copy Markdown

@jeffreybulanadi jeffreybulanadi commented Apr 25, 2026

Fixes #1198

Summary

The RecordSelection codeunit uses the page summary to determine which fields to show in the lookup list. This included Media and MediaSet fields, which are unhelpful in a list view as they render as empty strings or raw GUIDs.

Changes

RecordSelectionImpl.Codeunit.al

  • Added RemoveMediaFields procedure that filters Media and MediaSet fields from the page summary field list using the Field system table
  • Updated GetPageSummaryFields to accept a TableId parameter and call RemoveMediaFields after building the list
  • Updated callers ToText and GetFieldsFromPage to pass TableId

RecordSelectionTestTable.Table.al

  • Added a SomeMedia Media field
  • Updated the Brick fieldgroup to include SomeMedia so the regression scenario is covered

RecordSelectionTest.Codeunit.al

  • Added RecordSelectionMediaFieldsNotIncludedTest to verify Media fields are excluded from the field count
  • Added RecordSelectionToTextSkipsMediaFieldsTest to verify ToText output is not affected by Media fields

Issue microsoft#1198: The RecordSelection codeunit uses NavPageSummaryALFunctions.GetSummaryFields
to determine which fields to display in the record lookup list. This included Media and
MediaSet fields, which render as meaningless GUIDs or empty values in a list view.

Fix: Add RemoveMediaFields procedure that filters Media and MediaSet fields out of the
page summary field list before populating the Record Selection Buffer. This mirrors the
existing RemoveMediaAndBlobFields pattern from PageSummaryProviderImpl.

- Added RemoveMediaFields(TableId, PageSummaryFieldList) local procedure
- Updated GetPageSummaryFields to accept TableId and call RemoveMediaFields
- Updated callers ToText and GetFieldsFromPage to pass TableId
- Added SomeMedia field and updated Brick fieldgroup in test table to cover regression
- Added RecordSelectionMediaFieldsNotIncludedTest and RecordSelectionToTextSkipsMediaFieldsTest

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 25, 2026 03:59
@jeffreybulanadi jeffreybulanadi requested a review from a team as a code owner April 25, 2026 03:59
@github-actions github-actions Bot added AL: System Application From Fork Pull request is coming from a fork labels Apr 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the System Application’s Record Selection implementation to avoid showing Media/MediaSet fields in lookup summaries, aligning the lookup list output with what is meaningful in list contexts.

Changes:

  • Filter Media/MediaSet fields out of the page summary field list before building lookup rows / ToText output.
  • Extend the Record Selection test table with a Media field and include it in the Brick fieldgroup.
  • Add regression tests for excluding Media fields from the displayed field set and ToText output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/System Application/App/Record Selection/src/RecordSelectionImpl.Codeunit.al Adds Media/MediaSet filtering when deriving fields from page summary, and threads TableId through summary retrieval.
src/System Application/Test Library/Record Selection/RecordSelectionTestTable.Table.al Adds a Media field and includes it in the Brick fieldgroup to reproduce the problematic scenario.
src/System Application/Test/Record Selection/src/RecordSelectionTest.Codeunit.al Adds tests intended to validate Media fields are excluded from field count and ToText.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +148 to +163
RecordSelectionImpl: Codeunit "Record Selection Impl.";
TempRecordSelectionBuffer: Record "Record Selection Buffer" temporary;
PrimaryKeyCaptions: array[10] of Text;
FieldCount: Integer;
begin
// [SCENARIO] Media fields in the page summary are excluded from the record selection display.
// [GIVEN] Data in the test table which has a Media field in the Brick fieldgroup
Initialize();
PermissionsMock.Set('Rec. Selection Read');

// [WHEN] GetRecordsFromTableId is called for the table
FieldCount := RecordSelectionImpl.GetRecordsFromTableId(Database::"Record Selection Test Table", PrimaryKeyCaptions, TempRecordSelectionBuffer);

// [THEN] The media field is not included in the field count
Assert.AreEqual(3, FieldCount, 'Media fields should be excluded from the field count.');
Assert.AreEqual('', PrimaryKeyCaptions[4], 'Media field caption should not be present in the captions.');
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Record Selection Impl. has Access = Internal in the Record Selection app, but this test app is not listed in that app's internalsVisibleTo (it only exposes internals to Record Selection Test Library). As a result this reference will not compile from the Record Selection Test extension. Consider either (1) adding Record Selection Test to internalsVisibleTo in Record Selection/app.json, or (2) moving/wrapping this assertion via the Test Library (which already has internal access), or (3) rewriting the test to validate behavior through the public Record Selection API.

Suggested change
RecordSelectionImpl: Codeunit "Record Selection Impl.";
TempRecordSelectionBuffer: Record "Record Selection Buffer" temporary;
PrimaryKeyCaptions: array[10] of Text;
FieldCount: Integer;
begin
// [SCENARIO] Media fields in the page summary are excluded from the record selection display.
// [GIVEN] Data in the test table which has a Media field in the Brick fieldgroup
Initialize();
PermissionsMock.Set('Rec. Selection Read');
// [WHEN] GetRecordsFromTableId is called for the table
FieldCount := RecordSelectionImpl.GetRecordsFromTableId(Database::"Record Selection Test Table", PrimaryKeyCaptions, TempRecordSelectionBuffer);
// [THEN] The media field is not included in the field count
Assert.AreEqual(3, FieldCount, 'Media fields should be excluded from the field count.');
Assert.AreEqual('', PrimaryKeyCaptions[4], 'Media field caption should not be present in the captions.');
RecordSelection: Codeunit "Record Selection";
begin
// [SCENARIO] Media fields in the page summary are excluded from the record selection display.
// [GIVEN] Data in the test table which has a Media field in the Brick fieldgroup
Initialize();
PermissionsMock.Set('Rec. Selection Read');
// [WHEN] ToText is called for the table record through the public API
// [THEN] The media field is not included in the resulting text
Assert.AreEqual(ExpectedTextTok, RecordSelection.ToText(Database::"Record Selection Test Table", SystemId), 'Media fields should be excluded from the record selection text.');

Copilot uses AI. Check for mistakes.
Comment on lines 174 to 177
GenericList := NavPageSummaryALFunctions.GetSummaryFields(PageId);

foreach PageSummaryField in GenericList do
PageSummaryFieldList.Add(PageSummaryField);
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NavPageSummaryALFunctions.GetSummaryFields(PageId) can return null (other code in this repo guards it with IsNull(GenericList)). Here foreach PageSummaryField in GenericList would throw at runtime, preventing the intended fallback to primary-key fields. Add an IsNull(GenericList) check and treat it as “no summary fields” (e.g., return false / FieldCount := 0).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: System Application From Fork Pull request is coming from a fork

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RecordSelection should not display Media Fields

2 participants