Hi Alex,
First, thanks for your interest. I registered a plugin on "Associate" message with no primary and secondary entity defined. The code itself, as follows. I profiled the plugin and I got nothing when adding a new user to access team. On the other hand, I added a user to a "regular" team on Teams administration and the profiler got triggered.
EntityReference targetEntity = null;
string relationshipName = string.Empty;
EntityReferenceCollection relatedEntities = null;
EntityReference relatedEntity = null;
if (context.MessageName == "Associate") {
// Get the "Relationship" Key from context
if (context.InputParameters.Contains("Relationship")) {
relationshipName = context.InputParameters["Relationship"].ToString().SchemaName;
}
// Check the "Relationship Name" with your intended one
if (relationshipName != "teammembership_association") {
return;
}
// Get Entity 1 reference from "Target" Key from context
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) {
targetEntity = (EntityReference)context.InputParameters["Target"];
}
// Get Entity 2 reference from " RelatedEntities" Key from context
if (context.InputParameters.Contains("RelatedEntities") && context.InputParameters["RelatedEntities"] is EntityReferenceCollection) {
relatedEntities = context.InputParameters["RelatedEntities"] as EntityReferenceCollection;
relatedEntity = relatedEntities[0];
}
if(
(relatedEntity.LogicalName == "systemuser" && targetEntity.LogicalName == "team")
||
(relatedEntity.LogicalName == "team" && targetEntity.LogicalName == "systemuser")
)
{
// MY CODE HERE.
}
}