When merging records in Dynamics 365, all lookups referencing the deactivated record will be replaced with the master record.
Currently there is no way to change this configuration in Dynamics 365, even if the Relationship Behaviour has been set to Configurable Cascading, you can’t change the Merge setting because the dropdown list is disabled.
For this solution I chose to use a Plugin that runs on pre-update, because you can modify the lookup without changing the modified by user, thus keeping the audit history intact. Also I need to use a plugin because I can access to the Lookup values pre and post update.
For my example the case has a field called “Firm being merged”, which is an Account lookup field. The “Firm being merged” will be merged with the Customer.
When the two Accounts are merged it will trigger the update of all lookups with the reference to the deactivated Account in this instance “Barbara”.
Running the plugin on the Case pre-update and filtering on the firm being merged field (mag_firmbeingmergedid), allows us to trigger the plugin code for the merged lookup update.
Note: I an used “.Get”, which is an extension that Magnetism uses, without this you will need to check if the attribute exists and then use “.GetAttributeValue()”.
The Pre Image will contain the parameters: customerid, mag_firmbeingmergedid and mag_itemid
I only want to check Cases with an item (mag_item) of “Merge Firm”.
Then the important part is to compare the changes with the current record data.
If the “mag_firmbeingmergedid” has data and current “customerid” equals the same as the changed “mag_firmbeingmergedid”, then I know this is the merged update.
I will then update the target “mag_firmbeingmergedid” to the value of the existing “mag_firmbeingmergedid” to retain the original value.