Today I would like to share another mini tip about Business Central, how to get current profile ID via AL. I saw this question on the D365 forum the other day and realized it hadn’t been discussed separately, so I’ll talk about it briefly this time.
As you might know, on the My Settings page, you can see and change basic settings for your Business Central. For example, The Role (Profile). The role determines the home page, a starting screen that is designed for the needs of a specific role in an organization.
What should we do if we want to get the current user’s Profile ID while customizing? In fact, this is not very difficult, we only need to use SessionSettings data type to do it.
SessionSettings data type is a complex data type for passing user personalization settings for a client session as an object. The object contains properties that correspond to the fields in the system table 2000000073 User Personalization, including: App ID, Company, Language ID, Locale ID, Profile ID, Scope, and Time Zone.
You can use the AL methods of the SessionSettings data type to get, set, and send the user personalization settings for the current client session.
Let’s look at a simple example.
Very simple, give it a try!!!😁
PS: The following methods are available on instances of the SessionSettings data type
|Gets or sets the company property in a SessionSettings object.
|Populates the instance of a SessionsSettings with the current client user’s personalization properties (such as Profile ID and Company) that are stored in the database.
|Gets or sets the language ID property in a SessionSettings object.
|Gets or sets the locale ID property in a SessionSettings object.
|Gets or sets the ID of an extension, which provides a profile, in a SessionSettings object.
|Gets or sets the profile ID property in a SessionSettings object.
|Gets or sets the profile scope property in a SessionSettings object.
|Passes a SessionSettings object to the client to request a new session that uses the user personalization properties that are set in the object. The current client session is abandoned and a new session is started.
|Gets or sets the time zone property in a SessionSettings object.
So in addition to Profile ID, we can also get other information through SessionSettings data type.
More details: SessionSettings Data Type (A complex data type)
Hope this will help.
Thanks for reading.