Security privilege access to the user – D365 finance and operations

To check that user has access to specific privilege in d365 finance and operation use below code

    // <summary>
    /// check user has privilige access
    /// </summary>
    /// <param name = "_privilege">privilege identifier as string</param>
    /// <param name = "_userID">UserId</param>
    /// <returns>boolean</returns>
    public static boolean checkUserHasPrivilgeAccess(str _privilege, UserId _userID = curUserId())
    {
        UserInfo userInfo;
        SecurityUserRole securityUserRole;
        SecurityPrivilege securityPrivilege;
        SecurityRolePrivilegeExplodedGraph securityRolePrivilegeExplodedGraph;

        select firstonly RecId, Id, ObjectId, networkDomain from userInfo
            exists join securityUserRole where securityUserRole.User == _userID
            exists join securityRolePrivilegeExplodedGraph 
                where securityRolePrivilegeExplodedGraph.SecurityRole == securityUserRole.SecurityRole
            exists join securityPrivilege 
                where securityPrivilege.RecId == securityRolePrivilegeExplodedGraph.SecurityPrivilege 
                && securityPrivilege.Identifier == _privilege;

        return userInfo.RecId;
    }

You can get privilege identifier from SecurityPrivilege table using privilege name or description

Leave a comment if you have any question.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.