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 type | Field number | Description |
---|---|---|---|---|
SystemCreatedAt | $systemCreatedAt | DateTime | 2000000001 | Specifies the data and time that the record was created. |
SystemCreatedBy | $systemCreatedBy | GUID | 2000000002 | Specifies security ID (SID) of the user that created the record. |
SystemModifiedAt | $systemModifiedAt | DateTime | 2000000003 | Specifies the data and time that the record was last modified. |
SystemModifiedBy | $systemModifiedBy | GUID | 2000000004 | Specifies the SID of the user that last modified the record |
If we simply add it to the page, this will only show the GUID (User Security Id).


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
コメント