Search code examples
mergedynamics-crmdynamics-crm-2013

Dynamics CRM. Change Lead - Note default merge relationship


We have the following problem in Dynamics CRM 2013. When we merge two leads, normally everything related to those two leads is merged, including the notes records (annotations). The problem is that when the notes are merged they do not preserve the original owner that they had but they are assigned to the main lead owner.

I understand this is by default and there is no direct solution to this because even when changing the relationship to "Configurable Cascading" still the delete and merge relationships can't be changed.

But I wanted to know if there is any third party solution to this which can help us preserve the owner because otherwise when the leads are merged we have no idea who wrote the note originally in the old lead.

I do not know if I was clear enough on what I need so I am attaching this thread too which has remained unanswered and talks exactly about the problem we have:

https://community.dynamics.com/crm/f/117/t/109936

So my question is exactly the same of the last reply in the thread above... Is there any third party solution or plugin which we can develop to preserve the note records ownership after the lead merge?

Thank you


Solution

  • It should be possible to do it using a very simple plugin - simply create a plugin which will be running on Pre-Update of Note (annotation). In the plugin you should be able to get the original message name (by checking the Parent Context) which should be Merge Message. In case it's Merge message, simply remove owner from updated attributes. This would look something like:

    public void Execute(IServiceProvider serviceProvider)
    {
        var context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;
        if(context.ParentContext?.MessageName == "Merge")
        {
            var target = context.InputParameters["Target"] as Entity;
            target.Attributes.Remove("ownerid");
            target.Attributes.Remove("owningbusinessunit");
        }
    }
    

    I just checked that it works just fine. Of course to reduce performance impact, you should register this plugin with attributes filtering and run it only when Owner is about to change (you specify this attributes in Plugin Registration Tool).

    As you can see, plugin is pretty generic, so you can register it on any entity not only on Notes