Monday 9 January 2012

AssginSecurity Roles for existing user in crm2011 by C#

 protected void AssignSecurityRole(Guid prmUserId, Guid prmSecurityRoleId, IOrganizationService prmCrmWebService)
        {
            // Create new Associate Request object for creating a N:N link between User and Security
            AssociateRequest wod_AssosiateRequest = new AssociateRequest();
           
            // Create related entity reference object for associating relationship
            // In our case we will pass (SystemUser) record reference  

            wod_AssosiateRequest.RelatedEntities = new EntityReferenceCollection();
            wod_AssosiateRequest.RelatedEntities.Add(new EntityReference("systemuser", prmUserId));


            // Create new Relationship object for System User & Security Role entity schema and assigning it 
            // to request relationship property

            wod_AssosiateRequest.Relationship = new Relationship("systemuserroles_association");


            // Create target entity reference object for associating relationship
            wod_AssosiateRequest.Target = new EntityReference("role", prmSecurityRoleId);


            // Passing AssosiateRequest object to Crm Service Execute method for assigning Security Role to User
            prmCrmWebService.Execute(wod_AssosiateRequest);
        }
This code available in MSDN Library.

2 comments:

  1. Why do we use execute method ?

    ReplyDelete
  2. “Execute” method retrieving the context object inside given template can be used to create a plugin for the MS CRM 2011

    ReplyDelete