Hi,
CRM 2011, on-premises
Requirement: The plugin logic is when a new User gets created in the system, a Security Role needs to be added against this new User record.
This plugin is registered on Create message, Post stage, also registered with a Post Image step.
When the plugin fires I can see the post image has details of the newly created user details including the Id. However when Execute method execute with AssociateRequest it fails with a OrganizationServiceFault exception message
“usersettings With Id = dce6e02a-f373-e111-988b-0050569e0028 Does Not Exist” , and then it roles back the transaction.
The exception doesn’t have much details either. Any idea why the error is causing especially the plugin is registered as Post.
//Code to Associate
var userToRole = new AssociateRequest()
{
Target = new EntityReference(SystemUser.EntityLogicalName, userId),
RelatedEntities = new EntityReferenceCollection()
{
new EntityReference(Role.EntityLogicalName, role.RoleId)
},
Relationship = new Relationship("systemuserroles_association")
};
service.Execute(userToRole);
Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".