Skip to main content

3 Ways to GET a Record


We all know to do a GET of one record based on values of the primary key fields. The standard syntax is as follows:

[Ok :=] Record.Get(PK1[Value], PK2[Value],...).

Example would be like:

SalesHeaderFind.FindFirst();
SalesHeaderGet.Get(SalesHeaderFind."Document Type", SalesHeaderFind."No.");

The most used one, isn’t it? What if I tell you that there is a way to make this code shorter.

SalesHeaderGet.Get(SalesHeaderFind.RecordId);

Yes! It will! This is because RecordID is already the primary key itself and not one of the fields that forms it, as the method expects.

Also be aware that in case that the primary key field is of type RecordID you cannot use GET. In this case you will have to use the SetRange method.

And the last one as of Business Central 2019 release wave 2 there is a new method, GetBySystemId. The syntax is as follows.

[RecordExists := ]  Record.GetBySystemId(SystemId: Guid)

Example would be like:

SalesHeaderGet.GetBySystemId(SalesHeaderFind.SystemId);

Every record has a SystemId, which is stored in the SystemId field of the table. The SystemId cannot be changed.

Here is example to try it yourself:


Comments

Popular posts from this blog

Prepare For Certification - MB-820: Microsoft Dynamics 365 Business Central Developer

And finally, after around 10 years there is a certification again for Business Central Developers. Since there is no official book there are few ways to prepare by using online resources. Do not take this exam for granted event the old one was not easy even for the experienced developers :D nevertheless I hope that following links will help you prepare as best as possible. Review the study guide: Study guide for Exam MB-820: Microsoft Dynamics 365 Business Central Developer | Microsoft Learn Complete the training: Course MB-820T00---A: Dynamics 365 Business Central Developer - Training | Microsoft Learn There are also instructor materials available on GitHub that you can access for free: MicrosoftLearning/MB-820-Business-Central-Developer-Certification (github.com) What can I say more happy preparation 😊

Story about Sorting - Microsoft Dynamics 365 Business Central

                Back in the days it was so easy, right? Design a table, add any field as a secondary key, and use it as you like to sort the data and do any calculation you like. Nowadays you have no access to base tables therefore the only option is to make extension of table definition. I won’t speak much about this since it is very nicely described in Microsoft documentation: Table Keys - Business Central | Microsoft Learn                 What I want is to review are a few possibilities of data sorting you can use in Business Central and, here is the nice part, regardless of are the fields part of the keys or not! Let’s start by creating a simple table for this purpose: And also, the page: Publish and enter some data for example like this: Notice that data is always sorted by primary key by default. So, let’s play. I will use actions to sort the data differently, so let’s add some actions to sort the date using the SetCurrentKey function: SetCurrentKey Function (Record) - Dy

How to? Integrate into new posting routine V19 – Businesses central.

Since V19 Microsoft has introduced a new posting interface. Depending how you concepted your integration in to a posting routine you might have to refactor your code. Let’s start by looking into what has changed. What we have now from Microsoft is a codeunit 825 "Sales Post Invoice Events" in this codeunit you can find a bunch of publishers that will enable you to integrate into a function from codeunit 80 (for newbies this is the codeunit that handles posting in Sales transferring Sales Order to a Posted Sales Invoice for example). To integrate your logic into posting for any new application you are developing you can use these publishers and find a specific point that suits you the most. Alternatively, you can implement interface "Invoice Posting" if it suits you better. Another change is that the table 49 "Invoice Post. Buffer" is discontinued. Yap! A little bit about this table, in general it is a preparation table for the lines in order for them