Tuesday, January 27, 2026

Find privilege assigned to a user role

public void init()
    {
        next init();
 
        UserInfo                  userInfo;
        SecurityUserRole          securityUserRole;
        SecurityPrivilege         securityPrivilege;
        SecurityRolePrivilegeExplodedGraph securityRolePrivilegeExplodedGraph;
 
        select firstonly RecId from userInfo
        exists join securityUserRole
            where securityUserRole.User == curUserId()
        exists join securityRolePrivilegeExplodedGraph
            where securityRolePrivilegeExplodedGraph.SecurityRole == securityUserRole.SecurityRole
        exists join securityPrivilege
            where securityPrivilege.RecId == securityRolePrivilegeExplodedGraph.SecurityPrivilege
                && securityPrivilege.Identifier == 'YOURPRIVILEGENAME'
                && securityUserRole.AssignmentStatus == RoleAssignmentStatus::Enabled
                && (securityUserRole.ValidFrom < DateTimeUtil::utcNow() || securityUserRole.ValidFrom == utcDateTimeNull())
                && (securityUserRole.ValidTo > DateTimeUtil::utcNow() || securityUserRole.ValidTo == utcDateTimeNull());
 
 
        // Check if the user has a specific security privilege
        if (userInfo.RecId)
        {
            // Find the control and hide it
            FormStringControl control = this.design().controlName(formControlStr(HcmWorkerV2, SN));
            if (control)
            {
                control.visible(false);
            }
        }
    }

Table browser URL in D365FO

Critical Thinking icon icon by Icons8