Dynamics 365 Business Central: How to display User Name from SystemCreatedBy/SystemModifiedBy field on the page (Translate a user security ID GUID to the corresponding user name)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to display User Name from SystemCreatedBy/SystemModifiedBy on the page. This is a question I saw in the Business Central Forum this morning. More details: how to display username from systemcreatedby in page?

The SystemCreatedBy/SystemModifiedBy fields are system fields. System fields are fields that are automatically included in every table object by the platform. Dynamics 365 Business Central includes the following system fields:

  • SystemId
  • Data audit fields
  • Timestamp

Data audit fields: Every table in Business Central includes the following four system fields, which can be used for auditing records:Expand table

Field name (in AL)Column name (in database)Data typeField numberDescription
SystemCreatedAt$systemCreatedAtDateTime2000000001Specifies the data and time that the record was created.
SystemCreatedBy$systemCreatedByGUID2000000002Specifies security ID (SID) of the user that created the record.
SystemModifiedAt$systemModifiedAtDateTime2000000003Specifies the data and time that the record was last modified.
SystemModifiedBy$systemModifiedByGUID2000000004Specifies the SID of the user that last modified the record
APPLIES TO: Business Central 2020 release wave 2 and later

If we simply add it to the page, this will only show the GUID (User Security Id).

PS: Business Central 2023 wave 2 (BC23): Add existing table fields to optimize your pages (Adding Table Fields to Page without Page Extensions)

If we need to translate it into a user name, we need to do some more processing. In fact, this is mentioned in detail in MS Learn (Docs).

If you want to translate a user security ID GUID to the corresponding user name, the following AL code might be useful:

procedure GetUserNameFromSecurityId(UserSecurityID: Guid): Code[50]
    var
        User: Record User;
    begin
        User.Get(UserSecurityID);
        exit(User."User Name");
    end;

Let’s see a simple example.

Looks good.

Of course, this is not limited to list pages, but can also be used for other pages or objects. Give it a try!!!😁

PS: Dynamics 365 Business Central: User Security Id (SID) and User Id (Name)

Source code:

pageextension 50101 ZYItemListExt extends "Item List"
{
    layout
    {
        addafter(Description)
        {
            field(SystemCreatedBy; Rec.SystemCreatedBy)
            {
                ApplicationArea = All;
            }
            field(UserName; GetUserNameFromSecurityId(Rec.SystemCreatedBy))
            {
                Caption = 'User Name';
                ApplicationArea = All;
            }
        }
    }

    procedure GetUserNameFromSecurityId(UserSecurityID: Guid): Code[50]
    var
        User: Record User;
    begin
        User.Get(UserSecurityID);
        exit(User."User Name");
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL