Announcements
Hi,
My goal is to be able to get the data that shows what Security Roles have what privileges. Specifically, I am looking to get the data of record-level privileges for each security role. I am hoping to pull this data through the API (Odata Feed) so I can display in a Power BI report. I was able to find how users are related to security roles but I can not find out how Security Roles are related to their privileges specifically the record level privileges. Has anyone been able to do this before?
Any help is appreciated thank you!
Hi grant,club,
The RetrieveRolePrivilegesRole Function is what you are looking for.
var eachRolePrivileges = []; var roles = Xrm.Utility.getGlobalContext().userSettings.securityRoles; roles.forEach(function(item, i) { eachRolePrivileges[i] = retrieveRolePrivileges(item); }); retrieveRolePrivileges(roleId); function retrieveRolePrivileges(roleId) { var url = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest(); req.open( "GET", url "/api/data/v9.1/RetrieveRolePrivilegesRole(RoleId=" roleId ")", false ); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Prefer", 'odata.include-annotations="*"'); req.send(); if (req.readyState === 4) { if (req.status === 200) { var results = JSON.parse(req.response); return results.RolePrivileges; } else { console.log('err'); } } }
Thank you for your reply! Do you know if this information is available through the API to read in? I want to build something that updates consistently with the changes.
Hi grant.culp,
You can obtain this information with the Export Security Role tool in the XrmToolBox.
André Arnaud de Cal...
294,017
Super User 2025 Season 1
Martin Dráb
232,852
Most Valuable Professional
nmaenpaa
101,158
Moderator