Skip to content
Flexible record lookup in Business Central

Lookup any Record, from any Table

Daniel Gorski
Daniel Gorski June 07, 2023
2 min read

Have you ever wondered if you could create more flexible lookups? Maybe you have a function where the user is required to select a record from a specific table, depending on the situation?

As an example, let’s create a copy function for sales document comments.

Page.RunModal(0,Rec) is providing a hidden "feature". The compiler does not allow you to pass something like a RecordRef into the function, but it does allow you to pass a variant. And the most interesting thing is that the Variant will contain the value of the last record selected, when “RunModal = Action:LookUp” evaluates to true.

So, for example, we can apply a filter to a RecordRef (or the actual Record) according to the document type and pass the filtered record into a Variant. If we don’t need any pre applied filters, we just open the RecordRef or pass an unfiltered Record into the Variant.

For simplicity, we choose the RecordRef approach here, since the enumeration ordinals of “Sales Comment Document Type” conveniently match those of the “Sales Document Type” for the unposted documents.

AL code for the SelectRecord procedure that opens a RecordRef filtered by document type and returns the selected record's value through Page.RunModal and a Variant

This function enables us to quickly write a multi table lookup, returning the Document No. of the chosen Document Type.

The full source code of “Copy Sales Comments” can be found in our GitHub Repository.

https://github.com/byndit/BeyondAL

Related posts

▸ All posts
Upload and download files via BLOB in Business Central

Upload and Download Files in a BC Blob Field

January 29, 2025 · Daniel Gorski

Learn how to upload and download files in Business Central using a custom AL page and a BLOB field—perfect for storing documents, images, and more.

Read More
Read More: How to Upload and Download Files in a Blob Field in Business Central
Set up a custom BC25 repository

BC25 Base App Repo: Find All References in AL

September 19, 2024 · Daniel Gorski

Build your own BC25 repository from the base app, platform packages and assemblies so Find All References works across Microsoft's code in VS Code.

Read More
Read More: Increase Your DEV productivity with your own BC25 REPO
Fast data import with BeyondDataImporter

Lets import Data in a minute

June 11, 2024 · Daniel Gorski

Discover how to implement the BYD DI IProcessor interface to import data into Business Central in minutes – fast, structured and extendable.

Read More
Read More: Lets import Data in a minute