Update CRM 2011 Access Right Programmatically

2019-06-05 02:28发布

I would like to know if there is some way to update an Access Right in CRM 2011.

Let's say I have an Access Right named Marketing Manager which has user level privilege to create Account, I'd like to change this privilege to Organization level programmatically.

I'm waiting hopefully,

Thanks in advance

1条回答
萌系小妹纸
2楼-- · 2019-06-05 03:23

Please have a look at the code below. However it actually copy Role Privileges from existing Role to new Role. But I think it can give you an idea.

Guid existingRoleId = new Guid("C85F0FFF-4C80-E211-A877-1CC1DE79B4CA");
Guid newRoleId = new Guid("B6690FFF-4C80-E211-A877-1CC1DE79B4CA");

// Step 2
RetrieveRolePrivilegesRoleRequest getPrivilagesRequest = 
                 new RetrieveRolePrivilegesRoleRequest();

getPrivilagesRequest.RoleId = existingRoleId;
RetrieveRolePrivilegesRoleResponse privilagesResponse = 
         (RetrieveRolePrivilegesRoleResponse)service.Execute(getPrivilagesRequest);

if (privilagesResponse != null && privilagesResponse.RolePrivileges != null)
{
    // Step 3
    AddPrivilegesRoleRequest addPrivilagesRequest = new AddPrivilegesRoleRequest();
    addPrivilagesRequest.Privileges = privilagesResponse.RolePrivileges;
    addPrivilagesRequest.RoleId = newRoleId;
    AddPrivilegesRoleResponse addPrivilagesResponse = 
            (AddPrivilegesRoleResponse)service.Execute(addPrivilagesRequest);
}

Ref: Copy a security role programmatically – CRM 2011

Link 2

查看更多
登录 后发表回答