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

Dynamics 365 Business Central

Hi, Readers.
Recently I got some questions about User Id in Business Central.
So in this post, I would like to talk briefly about User Security Id (SID) and User Id (Name).

First of all, User Security Id and User Id are completely different in Business Central.

User Security Id, also known as User SID, is the unique identifier of the user, it is the primary key of the table 2000000120 User. The field type is Guid Data Type.

User Security Id: d98ace6a-0a17-419c-b2f1-bf6ab7858b49

Source Code:

User Id is the user name of the user account, it is not the primary key. The field type is Code Data Type.
User Id: ALANS

Source Code:

table 2000000120 User:

Another example, ADMIN on the Users (9800, List) page.

Business Central also provides two standard methods to get the User Security Id and User Id of the user that is logged on to the current session.

Database.UserSecurityId() Method: Gets the unique identifier of the user that is logged on to the current session.

The ID that is assigned to the user by the application. This is the value of the User Security ID field in table 2000000120, the User table, for the current user.

Database.UserId() Method: Gets the user name of the user account that is logged on to the current session.

This string contains the value of the User Name field in table 2000000120, the User table, for the current user.

For example,

User Security Id is ‘{6C67CC3E-7245-48CA-9946-1687D35055DF}’
User Id is ‘ADMIN’

As shown in the table 2000000120 User above, User Security Id is the primary key in the current BC environment, it is automatically generated when the user is created. But please note when the environment is different, the User Security Id of the same user is also different.

Sandbox213:

Sandbox214:

Production:

And User Security Id is not the Object ID in Azure Active Directory. More details: Find User (Object ID)

In some functions related to users, the User SID is generally used as the primary key.
User Settings List (9206, List):

And User SID is also used as Data audit fields:

The User Security ID is also used in some system standard functions. For example, in How to quickly check if the user has the SUPER permissions set via AL (Best practice)

Next let’s look at the User Id.
The User Id (User Name) is taken from the Username in Microsoft 365 when the user is created.

And the number will be added automatically if the name is duplicated.

In Business Central, the system allows you to rename the user and this will update the related records.

You are renaming an existing user. This will also update all related records. Are you sure that you want to rename the user?

Although the User Id (User Name) is not a primary key, it is not allowed to be duplicated. So in theory, this could also be used as a primary key to manage users.

Validation Results
The account YZHU already exists.

The standard did so as well. Some functions also use User Id (User Name) as the primary key in Business Central.
For example,

User Setup (91):


Warehouse Employee (7301):

As for the way they are related, you can find out from the table 2000000073 “User Personalization”, directly through the User table.

Well, in this post I have briefly shared some information about User Security Id (SID) and User Id. I hope it will give you some new tips on when to use them. Give it a try!!!😁

PS: User Security Id is not specific to BC, it has been around since NAV. And if your Credential Type is Windows, you can also find Windows Security Id.

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;

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL