Is it possible in Dynamics CRM 2016 to have a plugin that fires when any user's role assignments are changed?
If so, what message and entity would I register this plugin on?
You need to register plugin to Associate message,primary and secondary entity as none.
In plugin, you need to check for context.MessageName ("Associate" or "Disassociate") and context.InputParameters[“Relationship”] (we are looking for "systemuserroles_association")
code to check conditions would be something like that
//all usual plugin stuff here
if (context.InputParameters.Contains("Relationship")) {
relationshipName = context.InputParameters["Relationship"].ToString();
}
// Check the “Relationship Name” with your intended one
if (relationshipName != "systemuserroles_association") {
return;
}
if (context.MessageName == "Associate") {
//logic when role added
}
if (context.MessageName == "Disassociate") {
//logic when role removed
}
else {
//not interested
}
I haven't compiled the code, but it should give you idea how to proceed.