Monday, 31 March 2014

Update Organization Error - Microsoft.Crm.CrmException: Update Organization with Id=

Installing a Microsoft Dynamics CRM Rollup is an integral part of maintaining your system. However there are issues you may experience after you have completed the install, such as:

  • issues trying to launch CRM, which are now displaying an error message that isn't very useful.
  • importing a solution

Often the reasons for this is that the Organization itself has not been successfully upgraded. You can verify this by launching the Deployment Manager and checking the version as displayed below:

If you find that the version is incorrect, then you can right click on the specific Organization and use the Update option. At this point you may find yourself with a second issue, whereby the update itself is now failing:
Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction failed. InnerException: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: An item with the same key has already been added.

To remedy this, connect to the Organization's SQL Database using SQL Management Studio and execute the following script:

declare @IncidentOptionSetId uniqueidentifier = '7779161B-0E32-4001-8D44-339C2D1FF1F0'
declare @IncidentSystemPicklistIdFor1000 uniqueidentifier = 'DE3D1468-D2F4-4BC6-8BF6-73C5C64C435D'
declare @IncidentPicklistValueFor1000 int = 1000

declare @CategoryOptionSetId uniqueidentifier = '3041D03C-4166-4814-A2D4-1E3D93CAF2F1'
declare @CategorySystemPicklistIdFor1000 uniqueidentifier = 'ECBEE2BC-BAD2-4723-8612-371B4CE8D9E5'
declare @CategorySystemPicklistIdFor1001 uniqueidentifier = 'DE121D28-F5DF-45F7-B6FC-E97B1604F747'
declare @CategorySystemPicklistIdFor1002 uniqueidentifier = '8612EA04-81CF-423B-ADF4-EF74EEA70A41'
declare @CategoryPicklistValueFor1000 int = 1000
declare @CategoryPicklistValueFor1001 int = 1001
declare @CategoryPicklistValueFor1002 int = 1002
declare @CategoryPicklistValueFor6 int = 6
declare @CategoryPicklistValueFor7 int = 7
declare @CategoryPicklistValueFor8 int = 8

declare @SystemSolutionId uniqueidentifier = 'FD140AAD-4DF4-11DD-BD17-0019B9312238'
declare @AttributePicklistValueLabelTypeCode int = 2
declare @AttributePicklistValueSolutionComponentType int = 4
declare @DeleteComponentState int = 2

declare @PicklistIdMapping table
(
OldId uniqueidentifier,
NewId uniqueidentifier
)

delete @PicklistIdMapping
insert into @PicklistIdMapping (OldId, NewId)
 select AttributePicklistValueId, NULL
 from MetadataSchema.AttributePicklistValue 
 where 
  Value = @CategoryPicklistValueFor6 and AttributePicklistValueId = @CategorySystemPicklistIdFor1000
  or Value = @CategoryPicklistValueFor7 and AttributePicklistValueId = @CategorySystemPicklistIdFor1001
  or Value = @CategoryPicklistValueFor8 and AttributePicklistValueId = @CategorySystemPicklistIdFor1002
  -- do not include incident status picklist in here 
 group by AttributePicklistValueId 
 having COUNT(*) = 1


delete MetadataSchema.LocalizedLabel 
from
 MetadataSchema.LocalizedLabel l
 inner join @PicklistIdMapping m on l.ObjectId = m.OldId
 where l.LabelTypeCode = @AttributePicklistValueLabelTypeCode


delete DependencyBase where DependentComponentNodeId in 
(
 select DependencyNodeId 
 from 
  DependencyNodeBase d
  inner join @PicklistIdMapping m on d.ObjectId = m.OldId
  where d.ComponentType = @AttributePicklistValueSolutionComponentType
)

delete DependencyNodeBase 
from 
 DependencyNodeBase d
 inner join @PicklistIdMapping m on d.ObjectId = m.OldId
 where d.ComponentType = @AttributePicklistValueSolutionComponentType


delete MetadataSchema.AttributePicklistValue 
from 
 MetadataSchema.AttributePicklistValue a
 inner join @PicklistIdMapping m on a.AttributePicklistValueId = m.OldId


delete @PicklistIdMapping
insert into @PicklistIdMapping (OldId, NewId)
 select AttributePicklistValueId, NEWID() 
 from MetadataSchema.AttributePicklistValue 
 where 
  Value = @CategoryPicklistValueFor6 and AttributePicklistValueId = @CategorySystemPicklistIdFor1000
  or Value = @CategoryPicklistValueFor7 and AttributePicklistValueId = @CategorySystemPicklistIdFor1001
  or Value = @CategoryPicklistValueFor8 and AttributePicklistValueId = @CategorySystemPicklistIdFor1002
  -- do not include incident status picklist in here 
 group by AttributePicklistValueId 
 having COUNT(*) > 1

update MetadataSchema.LocalizedLabel
set ComponentState = @DeleteComponentState
from 
 MetadataSchema.LocalizedLabel l
 inner join @PicklistIdMapping m on l.ObjectId = m.OldId
 where l.SolutionId = @SystemSolutionId and l.LabelTypeCode = @AttributePicklistValueLabelTypeCode

update MetadataSchema.AttributePicklistValue 
set ComponentState = @DeleteComponentState
from 
 MetadataSchema.AttributePicklistValue a
 inner join @PicklistIdMapping m on a.AttributePicklistValueId = m.OldId
 where a.SolutionId = @SystemSolutionId

update MetadataSchema.LocalizedLabel 
set ObjectId = m.NewId 
from
 MetadataSchema.LocalizedLabel l
 inner join @PicklistIdMapping m on l.ObjectId = m.OldId
 where l.LabelTypeCode = @AttributePicklistValueLabelTypeCode

update DependencyNodeBase 
set ObjectId = m.NewId
from 
 DependencyNodeBase d
 inner join @PicklistIdMapping m on d.ObjectId = m.OldId
 where d.ComponentType = @AttributePicklistValueSolutionComponentType

update MetadataSchema.AttributePicklistValue 
set AttributePicklistValueId = m.NewId 
from 
 MetadataSchema.AttributePicklistValue a
 inner join @PicklistIdMapping m on a.AttributePicklistValueId = m.OldId

delete @PicklistIdMapping
insert into @PicklistIdMapping (OldId, NewId)
 select AttributePicklistValueId OldId,
  CASE Value
   WHEN @CategoryPicklistValueFor1000 THEN @CategorySystemPicklistIdFor1000
   WHEN @CategoryPicklistValueFor1001 THEN @CategorySystemPicklistIdFor1001
   WHEN @CategoryPicklistValueFor1002 THEN @CategorySystemPicklistIdFor1002
  END NewId
 from AttributePicklistValueView
 where OptionSetId = @CategoryOptionSetId and Value in (@CategoryPicklistValueFor1000, @CategoryPicklistValueFor1001, @CategoryPicklistValueFor1002)

delete from @PicklistIdMapping where OldId in (@CategorySystemPicklistIdFor1000, @CategorySystemPicklistIdFor1001, @CategorySystemPicklistIdFor1002)

insert into @PicklistIdMapping (OldId, NewId)
 select AttributePicklistValueId OldId, @IncidentSystemPicklistIdFor1000 NewId
 from AttributePicklistValueView
 where OptionSetId = @IncidentOptionSetId and Value = @IncidentPicklistValueFor1000
delete from @PicklistIdMapping where OldId = @IncidentSystemPicklistIdFor1000 

update MetadataSchema.LocalizedLabel 
set ObjectId = m.NewId 
from
 MetadataSchema.LocalizedLabel l
 inner join @PicklistIdMapping m on l.ObjectId = m.OldId
 where l.LabelTypeCode = @AttributePicklistValueLabelTypeCode

update DependencyNodeBase 
set ObjectId = m.NewId
from 
 DependencyNodeBase d
 inner join @PicklistIdMapping m on d.ObjectId = m.OldId
 where d.ComponentType = @AttributePicklistValueSolutionComponentType

update MetadataSchema.AttributePicklistValue 
set AttributePicklistValueId = m.NewId
from 
 MetadataSchema.AttributePicklistValue a
 inner join @PicklistIdMapping m on a.AttributePicklistValueId = m.OldId


After executing this script, try again and the Organization should not update successfully, which in return should resolve your CRM launching and solution import issues. 

Hope this helps?

Thursday, 27 March 2014

CRM 2011 - Shows Mobile View instead of the Default Website After Rollup

You may have experienced an issue when opening the MS CRM web client in a browser such as Firefox or IE whereby the mobile version of the CRM web client is loaded rather than the traditional default website view. This is most commonly seen after installing a roll up e.g. UR 12.

The difference is in the URL, just use the second address in order to load the correct web client.

Mobile: http://domainname/m/default.aspx

Default: http://domainname/main.aspx#

Action Microsoft.Crm.Setup.Common.Analyzer +CollectAction failed. Fatal error during installation

When installing the Srs Data Connection (Microsoft Dynamics CRM Reporting Extensions), you may have experienced the following error: ...