Well if you are reading this topic and thinking that there is already a whole lot of information available on how to register a plugin when a user is added to a team, then why this post again. Yes you are right. But I could see there is some incomplete information in many of the blog posts. So let’s see the complete picture. Many of you might already be aware of this. However still posting because it might be of some help.
Ok let’s start then. Say we register a plugin on the AddMembers message for the team entity. Going by SDK documentation, this should fire when we add a user to a team or when a team is assigned to a user. As you can see, I have regsitered a plugin for the AddMembers message for the team entity.
However when I manually go ahead and add a member to a team in CRM or when I add a existing team to a user through CRM Application, strangely the plugin does not fire. Search on this and you would find lot of very good blog posts that to handle this, register your plugin in the Associate message as shown in the below screenshot. And in the code handle the primary entity and the related entity.
Well so far so good and you would have surely come across this if you had ever to register a plugin when a user is added to a team. So does this mean that plugin on “AddMembers” does not fire under any circumstances. That’s not the case. But it fires under a different scenario.
Many a times you need to add a user to a team programmatically using the “AddMembersTeamRequest”. So when this request is executed, the associate message is not fired. instead this time the plugin registered on the “AddMembers” gets fired. Below I have written a code which associates a user to a team.
Below is the screenshot of what I get in the debugger of the registered plugin.
So register in the “associate” message when you are adding a user to a team from the CRM application. However if you are adding a user to a team programatically, register a plugin on the AddMembers message because associate won’t fire in that case.
Hope this helps!