Flexible record lookup in Business Central

Lookup any Record, from any Table

Daniel Gorski
Daniel Gorski 07. Juni 2023
2 Min. Lesezeit

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.

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

how-to
development
business central
lookup
recordref
variant
sales comments
Modulare ERP-Architektur für skalierbare Unternehmenssoftware

Architektur

Mehr als nur Warenwirtschaft - die Landtechnik Lösung

ERP-Systeme wurden jahrelang als Monolithen verkauft. Die eigentliche Stärke moderner Plattformen wie Business Central liegt jedoch in der Modularität - und gen

Read More
Read More
BeyondCues Subscription Billing KPIs in Business Central

Product

Subscription Billing Meets Real-Time KPIs: BeyondCues Sub. Billing

MRR, ARR, ARPU und Churn Rate direkt im Role Center von Business Central - ohne AL-Entwicklung. BeyondCues Sub. Billing bringt Subscription-KPIs dorthin, wo Sie

Read More
Read More