In Dynamics CRM 4.0 AssignUserRolesRoleRequest method was available to assign Security Roles to User but in CRM 2011 this method has been removed and no longer any special method is required to assign the Security Role to users, Security Roles are associated with Users via N:N relationship (relationship name: systemuserroles_association). So now in CRM 2011 we can use AssosiateRequest to assign the security roles to the user programmatically.
[C# Code]:The following C# code can be used to assign Security Role to a User.
public 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); |
} |
Hello, I want remove the Security Role from an already existing user. Any idea how we can do that using C# code in CRM 2011 SDK.
ReplyDeleteHi Madhukar,
ReplyDeleteYou can remove the user already assigned security role via DisassociateRequest as mentioned in this blog post: http://worldofdynamics.blogspot.com/2011/10/dynamics-crm-2011-c-code-for-removing.html
hi can we create user in online crm...
ReplyDeleteHi,
ReplyDeleteYou can create a user from Settings-> System-> Administration-> Users, click on New button, enter user details and save record. You may also refer: http://www.youtube.com/watch?v=5u42IY3Zj94
If you want to create users using SDK then you can create it using CrmWebservice Create method or using CreateRequest
Entity wod_UserEntity = new Entity("systemuser");
wod_UserEntity["firstname"] = "First Name";
wod_UserEntity["lastname"] = "First Name";
wod_UserEntity["businessunitid"] = new EntityReference("businessunit", BusinessUnitGUID);
// For complete list of user entity OptionSet values, you may refer: http://msdn.microsoft.com/en-us/library/gg594411.aspx
wod_UserEntity["caltype"] = new OptionSetValue(0);
// You have to pass values into system required (valid for create)and application required attributes, for required systema ttributes you may also refer: http://msdn.microsoft.com/en-us/library/gg328525.aspx
wod_CrmWebService.Create(wod_UserEntity);
This comment has been removed by the author.
ReplyDeleteHi,
ReplyDeleteIs it possible to run / invoke crm plugin from webservice or web portal?
yeezy shoes
ReplyDeletesupreme
air jordan
nike max shoes
adidas gazelle sale
jordan shoes
nike shox
nike air vapormax
jordan shoes
yeezy
supreme new york
sadsadsad
xiaofang20191212
steroid satın al
ReplyDeleteheets
F3M8İ6