Home
Do you know how to convert Dynamics CRM managed solution to unmanaged
  v5.0 Posted at 22/01/2016 8:40 PM by Lu Zhang
​​You might need to modify solutions during migration. But if that solution is managed, you cannot edit directly. If you have the unmanaged version in development environment, you can edit it and override the production managed solution.

If you don't have the unmanaged version which is bad practice. see her​e for good practice about CRM ALM (How to avoid this section), use the following script to hack the org database

declare @solutionId uniqueidentifier, @systemSolutionId uniqueidentifier

-- specify the uniquename of the managed solution you'd like to unmanage here it is StagingOrg

select @solutionId = solutionid from SolutionBase where UniqueName='Your solution name'

-- DO NOT TOUCH FROM HERE ON --

select @systemSolutionId = solutionid from SolutionBase where UniqueName='Active'

update PublisherBase set IsReadonly=0

where PublisherId in (select PublisherId from SolutionBase where SolutionId=@solutionId)

print 'updated publisher'

declare @tables table (id int identity, name nvarchar(100), ismanaged bit, issolution bit)

declare @count int, @currentTable nvarchar(100), @currentM bit, @currentS bit, @sql nvarchar(max)

-- go through all the tables that have the ismanaged/solutionid flag, find the related records for the current solution and move them to the crm active solution.

insert into @tables (name, ismanaged, issolution)

select name, 1, 0 from sysobjects where id in

(select id from syscolumns where name in ('IsManaged'))

and type='U'

order by name

 

insert into @tables (name, ismanaged, issolution)

select name, 0, 1 from sysobjects where id in

(select id from syscolumns where name in ('SolutionId'))

and type='U' and name not in ('SolutionComponentBase') and name not like '%ribbon%' -- ignore this table because it doesn't make a difference. it does cause dependency errors on the exported solution but we can manually edit the xml for that.

order by name

 

select @count = count(*) from @tables

while (@count > 0)

begin

select @currentTable =name, @currentM =ismanaged, @currentS =issolution from @tables where id=@count

 

if (@currentM = 1)

begin

select @sql ='update ' + @currentTable + ' set IsManaged=0 where SolutionId=N''' + cast(@solutionId as nvarchar(100)) + ''''

exec (@sql)

 

print 'updated IsManaged to 0 on: ' + @currentTable

end

 

if (@currentS = 1)

begin

select @sql ='update ' + @currentTable + ' set SolutionId=N''' + cast(@systemSolutionId as nvarchar(100)) + ''' where SolutionId=N''' + cast(@solutionId as nvarchar(100)) + ''''

exec (@sql)

 

print 'updated SolutionId on: ' + @currentTable

end

 

select @count = @count -1, @currentTable = NULL

end

 

Thanks the author Gayan Perera who demos this in the video https://channel9.msdn.com/Events/TechEd/NewZealand/TechEd-New-Zealand-2012/DYN401

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.