web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to modify access privilege in security role through c# code (WPF application)?

(0) ShareShare
ReportReport
Posted on by 1,157

Hi All,

I want to modify the 'User Enable/Disable' privilege to 'Business Unit/Organization'  in some Security Roles.

I want to do this operation through WPF application.  I have created a connection with CRM through WPF and retrieved all security roles but not able to modify the access privilege.

Could anyone have any idea how to do it?

Thanks,

Jayesh

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Did you try adding privilege (AddPrivilegesRoleRequest)?

    // Add the prvReadAccount privilege to the example roles to assure the
    // team can read accounts.
    AddPrivilegesRoleRequest addPrivilegesRequest = new AddPrivilegesRoleRequest
    {
        RoleId = _roleId,
        Privileges = new[] 
        {
            // Grant prvReadAccount privilege.
            new RolePrivilege
            { 
                PrivilegeId = readAccountPrivilege.Id 
            }
        }
    };
    _service.Execute(addPrivilegesRequest);
    

    https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addprivilegesrolerequest.aspx

    https://rajeevpentyala.com/tag/retrieveroleprivilegesrolerequest/

  • JayeshAC Profile Picture
    1,157 on at

    Thanks for the reply Gopalan.

    Yes, i have tried the same approach but i'm not able to see any difference in privileges in security role. Please see the my code snippet mentioned below:


    AddPrivilegesRoleRequest addPrivilegesRequest = new AddPrivilegesRoleRequest
    {
    RoleId = new Guid("42125738-C8E8-DD11-A7B9-0019B9F8F548"),
    Privileges = new[]
    {
    new RolePrivilege
    {
    Depth = PrivilegeDepth.Deep,
    PrivilegeId = new Guid("095860D1-42DE-4EFC-8D53-4B60E74D3D26")
    }

    }
    };
    crmConnection.Execute(addPrivilegesRequest);

    Please let me know if i'm doing anything wrong in this request.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans