Skip to main content

Posts

Showing posts from September, 2023
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(Sales