In Model-Driven Apps, implementing role-based logic often requires knowing the security roles assigned to the current user. Power Apps makes this possible through the Client API, which provides methods to retrieve both role IDs and names. This guide shows how to retrieve user security roles efficiently.
To get the list of role GUIDs assigned to the current user –
Xrm.Utility.getGlobalContext().userSettings.securityRolesThis returns an array of role IDs but does not include the role names.
To retrieve both the role names and their corresponding GUIDs, use –
Xrm.Utility.getGlobalContext().userSettings.roles.get()This returns an array of role objects, each containing the id and name of the security role, making it easier to implement role-based conditions or UI logic.
Check out other useful methods provided by the client API in the official documentation.