Monday, 10 September 2012

Tech Ed 2012

It has been a long time since my last post, anyhow currently I'm at Tech Ed and I figured I would blog about a cool session I attended regarding CRM 2011 and tips and tricks.

Gayan Perera from Magnetism ran the session and mentioned a really cool generation tool to replace the crmsvcutil tool from the sdk.  It has now been released on code plex and allows generation of code using templating, this is a lot more flexible than the current tool and easier to work with.  Check it out here: http://crm2011codegen.codeplex.com/

The other cool information was turning managed solutions into unmanaged solutions using SQL, it makes the org unusable but if done on an import of a copied database the solution can be exported and imported where required.

Kudos to Gayan and Thomas getting this SQL running:

declare @solutionId uniqueidentifier, @systemSolutionId uniqueidentifier -- specify the uniquename of the managed solution you'd like to unmanage
select @solutionId = solutionid from SolutionBase where UniqueName='Your Solution Name'
select @systemSolutionId = solutionid from SolutionBase where UniqueName='Active'

declare @sql nvarchar(max)
select @sql ='update PublisherBase set IsReadonly=0 where PublisherId in (select PublisherId from SolutionBase where SolutionId=N'''+cast(@solutionId as nvarchar(100))+''')'
print (@sql)
exec (@sql)

declare @isManagedTables table (id int identity, name nvarchar(100))
declare @count int, @currentTable nvarchar(100), @currentM bit, @currentS bit
-- 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 @isManagedTables (name)
select name from sysobjects where id in 
(select id from syscolumns where name in ('IsManaged')) 
and type='U'
order by name
select @count = count(*) from @isManagedTables
while (@count > 0)
begin
select @currentTable =name from @isManagedTables where id=@count
select @sql ='update ' + @currentTable + ' set IsManaged=0 where SolutionId=N''' + cast(@solutionId as nvarchar(100)) + ''''
print (@sql)
exec (@sql)
select @count = @count -1, @currentTable = NULL
end

declare @isSolutionIdTables table (id int identity, name nvarchar(100))
insert into @isSolutionIdTables (name)
select name from sysobjects where id in 
(select id from syscolumns where name in ('SolutionId')) 
and type='U' and name not in ('SolutionComponentBase') -- 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 @isSolutionIdTables
while (@count > 0)
begin
select @currentTable =name from @isSolutionIdTables where id=@count
select @sql ='update ' + @currentTable + ' set SolutionId=N''' + cast(@systemSolutionId as nvarchar(100)) + ''' where SolutionId=N''' + cast(@solutionId as nvarchar(100)) + ''''
print (@sql)
exec (@sql)
select @count = @count -1, @currentTable = NULL
end

-- Remove dependencies BaseSolutionId
delete from DependencyBase where DependentComponentNodeId in (
select DependencyNodeId from DependencyNodeBase where BaseSolutionId=@solutionId
)
alter table DependencyBase NOCHECK CONSTRAINT dependencynode_ancestor_dependency 
delete from DependencyNodeBase where BaseSolutionId=@solutionId
alter table DependencyBase CHECK CONSTRAINT dependencynode_ancestor_dependency

-- Remove dependencies TopSolutionId
delete from DependencyBase where DependentComponentNodeId in (
select DependencyNodeId from DependencyNodeBase where TopSolutionId=@solutionId
)
alter table DependencyBase NOCHECK CONSTRAINT dependencynode_ancestor_dependency 
delete from DependencyNodeBase where TopSolutionId=@solutionId
alter table DependencyBase CHECK CONSTRAINT dependencynode_ancestor_dependency

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi thanks for that Thomas, I have updated the blog with your sql, I look forward to seeing a solution to those sql errors you are receiving.

    ReplyDelete
    Replies
    1. Thanks Hadley,

      Could you please replace the line by:

      select @solutionId = solutionid from SolutionBase where UniqueName='The Unique Solution Name'

      I didn't want my solution name appears in the script.
      Thanks. I'm not able to edit my comment :)

      Delete