Thursday, August 16, 2012

Associate the Security Roles to System User

Below piece of C# code associate the Security Roles to specified System User in Microsoft Dynamics CRM 2011.

using Microsoft.Crm.Sdk.Messages;

EntityReference Monikar1 = new EntityReference();
Monikar1.Id = id;
Monikar1.Name = "systemuser";
AssociateEntitiesRequest associatedRequest = new AssociateEntitiesRequest();
associatedRequest.Moniker1 = new EntityReference
    Id = Monikar1.Id, LogicalName = Monikar1.Name 
};
associatedRequest.RelationshipName = "systemuserroles_association";

foreach (var role in securityRoles)
{
    EntityReference Moniker2 = null;
    Moniker2 = new EntityReference();
    Moniker2.Name = "role";
    Moniker2.LogicalName = "role";
    Moniker2.Id = new Guid(role.Id.ToString());
    associatedRequest.Moniker2 = new EntityReference
        Id = Moniker2.Id, LogicalName = Moniker2.LogicalName
    };
    service.Execute(associatedRequest);
}


3 comments:


  1. Thanks for sharing this authentic update. Have you found any new value pick. When u might be posting your next gem. Checking your blog daily for your next pick.

    Home Automation Vancouver | vancouver security | Best Security Vancouver

    ReplyDelete
    Replies
    1. Thanks. Here you go. http://charanmandya.blogspot.com/2016/01/MSCRM-Errors-Solutions.html
      And will keep updating.

      Delete
  2. Respected Sir,How we can create autonumber by using plugin ?

    ReplyDelete