Search code examples
dynamics-crmdynamics-crm-2016

How can I revert an unmanaged plugin from an org


I'm using dynamics crm 8.1.

I've connected to an org that has a plugin that is traditionally deployed to that org as part of a managed solution. I overwrote a plugin using the plugin registration tool. This plugin now is presumably an unmanaged asset that I expect will always sit on top of the managed version that is deployed as part of the solution.

How can I erase the unmanaged version of the plugin from the org so that future upgrades of the managed solution will apply to that org? I assume this involves a crm script of some kind.

Thanks!


Solution

  • Through some database reverse engineering, I've come up with an answer for my own question. This process worked for me, but I cannot guarantee that it will work for everyone.

    When a plugin assembly is replaced using plugin registration tool, it will do three things.

    1) The OverwriteTime column of the PluginAssemblyBase record for that plugin will be modified. 2) A new PluginAssemblyBase record will be added for the plugin's assembly that you just added. 3) The record in TopSolutionId column for the DependencyNodeBase record will be modified for the plugin.

    The reversal process for this was performed using the following SQL Query:

    BEGIN TRANSACTION
            DELETE dbo.PluginAssemblyBase 
            WHERE PluginAssemblyIdUnique <> @originalPluginAssemblyIdUnique and Name = @assemblyName and OverwriteTime = 0
    
            UPDATE dbo.PluginAssemblyBase SET
                OverwriteTime='1900-01-01 00:00:00.000'
            WHERE PluginAssemblyIdUnique = @originalPluginAssemblyIdUnique
    
            UPDATE dbo.DependencyNodeBase SET
                TopSolutionId = @ManagedSolutionId
            WHERE Objectid = @pluginAssemblyId
     COMMIT TRANSACTION
    

    That script can be used by others, but in addition to setting the variables, you may want to add some validation in there so that it isn't used under the wrong scenario.