Fix: RecordSelection should not display Media fields#7850
Fix: RecordSelection should not display Media fields#7850jeffreybulanadi wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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>
There was a problem hiding this comment.
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 /
ToTextoutput. - 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
ToTextoutput.
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.
| 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.'); |
There was a problem hiding this comment.
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.
| 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.'); |
| GenericList := NavPageSummaryALFunctions.GetSummaryFields(PageId); | ||
|
|
||
| foreach PageSummaryField in GenericList do | ||
| PageSummaryFieldList.Add(PageSummaryField); |
There was a problem hiding this comment.
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).
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
RecordSelectionTestTable.Table.al
RecordSelectionTest.Codeunit.al