Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

how to use RetrieveRolePrivilegesRole Function in web api? RetrieveRolePrivilegesRole Function

Posted on by 60
I want to retrieve all the privileges that are assigned to the specified role. So, I am using the RetrieveRolePrivilegesRole Function.
 
I tried using the above function in a REST API:
 
{organization_url}/api/data/v9.0/RetrieveRolePrivileges(RoleId=4931681d-8163-e811-a965-000d3a11fe32)
 
But, it is giving me an error:
 
/Resource not found for the segment 'RetrieveRolePrivileges'./
 
How can I resolve this error?
  • Suggested answer
    Haig Liu Profile Picture
    Haig Liu Microsoft Employee on at
    how to use RetrieveRolePrivilegesRole Function in web api? RetrieveRolePrivilegesRole Function
    Hi,
     
    First of all, if you only need to see all the permissions of a single role, I recommend you use the XrmToolBox tool below:
    It's easy and convenient enough.
    But regarding the RetrieveRolePrivilegesRole function, I got a clarification in a database related article.
    In a recent update, Microsoft has hidden the roleprivileges table from users, so querying permissions and roles in the database via SQL is no longer possible.
    The author of the article also provides a new database code:
     
            /// <summary>
            /// Get the set of all Roles that have the same permissions
            /// </summary>
            /// <param name="privilegename">Privilege name</param>
            /// <returns></returns
            public List<string> GetRoles(string privilegename)
            {
                List<string> list = new List<string>();
                Entity Privilege = GetPrivilege(privilegename);
                QueryExpression Query = new QueryExpression("role")
                {
                    Distinct = false,
                    NoLock = true,
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression()
                };
                Query.Criteria.AddCondition("parentroleid", ConditionOperator.Null);
                EntityCollection Collection = service.RetrieveMultiple(Query); foreach (var item in Collection.
                foreach (var item in Collection.Entities)
                {
                    RolePrivilege[] rolePrivileges = GetRolePrivileges(item.Id); var obj = rolePrivileges(item.
                    var obj = rolePrivileges.Where(t => t.PrivilegeId == Privilege.Id).FirstOrDefault();
                    if (obj ! = null)
                    {
                        list.Add(item["name"].ToString());
                        Console.WriteLine(item["name"].ToString());
                    }
                }
                Console.WriteLine(item["name"].ToString()); } }
            }
     
            /// <summary>
            /// Get all permissions under a Role
            /// </summary> /// Get all the permissions under a Role.
            /// <param name="roleId"></param>
            /// <returns></returns
            public RolePrivilege[] GetRolePrivileges(Guid roleId)
            {
                RetrieveRolePrivilegesRoleRequest request = new RetrieveRolePrivilegesRoleRequest();
                request.RoleId = roleId;
     
                RetrieveRolePrivilegesRoleResponse response = (RetrieveRolePrivilegesRoleResponse)service.Execute(request); if (response !
                if (response ! = null && response.Results ! = null)
                {
                    RolePrivilege[] rolePrivileges = (RolePrivilege[])response.Results["RolePrivileges"]; return rolePrivileges; return RolePrivileges; if (response ! = null && response.Results !
                    return rolePrivileges;
                }
                else
                {
                    throw new Exception($"Role {roleId} error"); }
                }
            }
     
            /// <summary>
            /// Getting permissions
            /// </summary>
            /// <param name="name">Permission name</param>
            /// <returns></returns
            public Entity GetPrivilege(string name)
            {
                QueryExpression Query = new QueryExpression("privilege")
                {
                    Distinct = false,
                    Distinct = false, NoLock = true, ColumnSet = new ColumnSet(string name) {
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression()
                };
                Query.Criteria.AddCondition("name", ConditionOperator.Equal, name);
                EntityCollection Collection = service.RetrieveMultiple(Query); if (Collection.Entities !
                if (Collection.Entities ! = null && Collection.Entities.Count > 0)
                Entities.Count > 0) {
                    return Collection.Entities[0];
                }
                if (Collection.Entities != null && Collection.Entities.
                {
                    throw new Exception($"Failed to query {name} permission"); }
                }
            }
     
    If my answer was helpful, please click Like, and if it solved your problem, I hope you can verify it to help other community members find more.
    Please feel free to contact me if you have any further questions.
    Regards,
    Haig

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans
Liquid error: parsing "/forums/thread/details/?threadid=%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))," - Too many )'s.