- Run the Below SQL Script
@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
- Go to Settings > Customizations > Solutions
- Export the Solution as Unmanaged
- Save and Extract the Solution File
- Open and Edit the solution.xml File
- Change the <Managed> Tag
Find the <Managed> tag within the solution.xml file, Change the value from 1 (Managed) to 0 (Unmanaged): - Remove All MissingDependency Elements
Scroll down towards the bottom of the solution.xml file, Remove all <MissingDependency> elements or self-close them like this: - Re-Zip the Content
- Import the Solution Back into CRM
No comments:
Post a Comment