locked
Programatically update Security Role - Urgent RRS feed

  • Question

  • Hi,

    Is there any way to update CRM Security role Programatically (Crmsdk)?

    I know we can create a custom role..
    For updating CRM Security role I am using the same methods which we can use for creating custom role. But it's not updating the CRM Role.

    Here is the code which I am using

    const

     

    string accountCreatePriv = "D26FE964-230B-42DD-AD93-5CC879DE411E";

     

    WhoAmIRequest whoAmIRequest = new WhoAmIRequest();

     

    WhoAmIResponse currentUser = (WhoAmIResponse)service.Execute(whoAmIRequest);

     

     

    RolePrivilege[] privileges = new RolePrivilege[1];

    privileges[0] =

    new RolePrivilege();

    privileges[0].PrivilegeId =

    new Guid(accountCreatePriv);

    privileges[0].Depth =

    PrivilegeDepth.Global;

     

    AddPrivilegesRoleRequest addPrivRequest = new AddPrivilegesRoleRequest();

    addPrivRequest.Privileges = privileges;

    addPrivRequest.RoleId =

    new Guid("982B88FF-2F10-DD11-AC20-00155D00BF02");

     

    AddPrivilegesRoleResponse addPrivResponse = (AddPrivilegesRoleResponse)service.Execute(addPrivRequest);

    Please let me know is this a right method to update CRM Roles or not please provide me solution.

    Thanks in advance...


    Parth Patel

     

    Monday, October 26, 2009 9:41 AM

Answers

  • You should be bale to update the privs, but you are trying to add a record that already exists and are probably getting an error thrown (Are you catching the error?).  Look into the removePrivilegeRole and replacePrivlegesRole actions.
    Matt, MVP - Dynamics CRM
    • Proposed as answer by Matt Parks Wednesday, October 28, 2009 3:57 AM
    • Marked as answer by Donna EdwardsMVP Monday, January 4, 2010 6:52 PM
    Wednesday, October 28, 2009 3:57 AM