Sometimes we need to get what all privileges a security role have, quickly without going into CRM standard security roles and find out.
Or if we want to keep the copy of privileges to different security roles as a reference to be used at some point of time in future, we have following sql query running which in sql server will give you list of name of security role, entity name with access level and security level:
SELECT DISTINCT FilteredRole.name, EntityView.PhysicalName AS [Entity Name], CASE Privilege.AccessRight WHEN 1 THEN ‘READ’ WHEN 2 THEN ‘WRITE’ WHEN 4 THEN ‘APPEND’ WHEN 16 THEN ‘APPENDTO’ WHEN 32 THEN ‘CREATE’ WHEN 65536 THEN ‘DELETE’ WHEN 262144 THEN ‘SHARE’ WHEN 524288 THEN ‘ASSIGN’ END AS [Access Level], CASE PrivilegeDepthMask WHEN 1 THEN ‘User’ WHEN 2 THEN ‘Business Unit’ WHEN 4 THEN ‘Parent: Child Business Unit’ WHEN 8 THEN ‘Organisation’ END AS [Security Level] FROM RolePrivileges INNER JOIN FilteredRole ON RolePrivileges.RoleId = FilteredRole.roleid INNER JOIN PrivilegeObjectTypeCodes ON RolePrivileges.PrivilegeId = PrivilegeObjectTypeCodes.PrivilegeId INNER JOIN Privilege ON RolePrivileges.PrivilegeId = Privilege.PrivilegeId INNER JOIN EntityView ON EntityView.ObjectTypeCode = PrivilegeObjectTypeCodes.ObjectTypeCode ORDER BY FilteredRole.name, [Entity Name]
Hope the results are helpful..!! 🙂
Do you have latest sql query for d365 because i have some problem when i try to run it in d365 crm.