Dynamics 365 Business Central: How to get a record by its SystemId

Dynamics 365 Business Central

Hi, Readers.
Recently I saw an interesting question, is there a way to do a GET on the SystemId field?
In this post, I would like to talk about SystemId field in Business Central.

The SystemId field is one of the system fields. And system fields are fields that are automatically included in every table object by the platform.

So, although it exists, it cannot be found in the Base Application.
For example, table 18 Customer

PS: You can force Business Central to run the Field table by adding the ?table=2000000041 parameter to the URL, such as in the following example: 
https://businesscentral.dynamics.com/d8f36038-1f93-4543-affc-5dc92b6ee871/Sandbox?table=2000000041

Then you can find that all tables have SystemId field.

The SystemId field is a GUID data type field that specifies a unique, immutable (read-only) identifier for records in the table. The SystemId field has the following characteristics and behavior:

APPLIES TO: Business Central 2019 release wave 2 and later

  • All records must have a value in the SystemId field.
  • You can assign your own value when a record is inserted in the database. Otherwise, the platform will automatically generate and assign a value. (The Insert(Boolean, Boolean) lets you specify the SystemId value for a record, instead of using one assigned by the platform)
  • Once the SystemId has been set, it can’t be changed.
  • There’s always a unique secondary key on the SystemId field to ensure records don’t have identical field values.
  • The SystemId field is given the field number 2000000000.

APPLIES TO: Business Central 2020 release wave 2 and later

  • If the SystemId field is specified in a Web Service POST request, the OData stack persists the value in the database.
  • The SystemId field can be used as part of a (non-primary) key.
  • You can show the SystemId field as a field on a page.
  • You can link FactBoxes/page parts using the SystemId field.

The SystemId field is exposed in the platform code and for AL code, allowing you to code against it. For example:

1. RecordRef.SystemIdNo Method: Gets the field number that is used by the SystemId field.

2. Record.GetBySystemId Method: Gets a record by its SystemId.

First, the TableRelation Property lets you use the SystemId field to set up table relationships.

For example: Shipment Method Id

If you click the id, you can see Code and Description.

So, you can use Shipment Method Id to get code, description, and any value in Shipment Method table.
For example,

Sample Code:

pageextension 50100 "Copy Customer Ext" extends "Customer List"
{

    actions
    {
        addafter(PaymentRegistration)
        {
            action(GetBySystemId)
            {
                Caption = 'Get by System ID';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                Image = GetSourceDoc;

                trigger OnAction()
                var
                    Cust: Record Customer;
                    Msg01: Label 'The shipment method system Id is: %1.';
                    Msg02: Label 'The shipment method description is: %1.';
                    ShipmentMethod: Record "Shipment Method";
                begin
                    Cust.Reset();
                    CurrPage.SetSelectionFilter(Cust);
                    if Cust.FindFirst() then begin
                        Message(Msg01, Cust."Shipment Method Id");
                        if ShipmentMethod.GetBySystemId(Cust."Shipment Method Id") then
                            Message(Msg02, ShipmentMethod.Description);
                    end;
                end;
            }
        }
    }
}

Test Video:

3. You can show the SystemId field as a field on a page.

4. The SystemId field can be used as a binding key to an API.

Find out more about SystemId field from Microsoft Docs.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL