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#

Thursday, 9 January 2014

Microsoft Dynamics Solutions - Management & Best Practices

This post is to help clarify what the best approach is to manage and use Microsoft Dynamics CRM Solutions to distribute your customizations and software components through your various CRM Environments, from Development, QA, Staging and Production.

That said, there isn't really an ultimate approach which is 100% right or 100% wrong, rather each with its own pro's and con's.

Managed vs. Unmanaged
I don't want to go too deep into the differences between managed and unmanaged solutions, but it is important for you to understand why you would use one and not the other, based on your requirements.

Unmanaged
Commonly this is referred to as the source, where you can distribute the solution to a different CRM organization, but with the added flexibility of having the ability to further making changes to what has been installed. For example if there was a new entity, which a screen you didn't like the look of, then you have the ability to make changes to that screen.

You cannot uninstall a unmanaged solution, you have to individually delete each company manually.

Installing different versions of the same solution will just overwrite what was installed by the previous version, there is no unmanaged solution layering based on versions.

Managed
Commonly referred to as the compiled or build version. The main reason to use this, is to protect your solution. For example if you are a software vender which has built a great add-on solution, you want to sell this solution but do not want others being able to further customize or copy your hard work. There is an exception to the rule, where you do have the flexibility to mark specific components as customizable,  a good workaround if there was a scenario where you did want to give the option to change a specific part of your solution.

All managed solutions can be uninstalled, which automatically removes all components that were installed as part of that solution.

Managed Solutions can also be layered, this is where different versions of the same solution can be installed on top of each other. For example, version 2.0 of a solution can be installed on top of version 1.0. Now if there was an issue with version 2.0 and you needed to rollback, then you can uninstall 2.0 which would revert the system back to version 1.0.

What are the Options?
1. Single Solution - this is where all customization's and components are distributed within a single solution file

2. Multiple Solutions - where components are split into various solutions, for example:
Pro's & Con's
Single Solution
  • Pro's
    • Less dependency issues
    • Everything in one place, single install
    • All components have one version
  • Con's
    • Solution can become large
    • Releasing a change to a single component will require releasing all components in the solution. Developers who have incomplete items can become a bottleneck
    • Incomplete customization's can accidentally be exported and included in the solution
    • Cannot use different versions for different components. 
Multiple Solutions
  • Pro's
    • Smaller solutions
    • Categorize components into relevant solutions
    • Developers can work on components in different solutions in parallel with less concern of exporting incomplete customization's, or becoming a block point for a solution export
    • Don't have to release everything, only the solution that has a change 
    • Better Granularity with solution versioning, as each solution can have its own version number
  • Con's
    • Installation will fail if dependent components do not exist, dependent solutions must be installed prior. Thus the order by which the solutions are installed becomes very important.
    • More than one solution is required to fully install your entire solution, as the various components are split between several solutions
    • Rollback requires you to uninstall each solution
Conclusion
Many times I've had to make the decision, whether to go with a single or multi solution approach. I have devised an easy method of selection, depending how and who you are targeting the solution for.

Single Solution
Software House - if you plan on targeting your solution for sale as a product based solution, then I would recommend using a single solution as the release cycle for this product will be managed by you the software vendor and your customers would expect an easy upgrade process between versions. Also simplifies the uninstalling process for the customer.

Multi Solution
In House - for an internal CRM project. Having the ability to make changes and perform smaller releases and hot fixes outside major releases are much more likely. Think about all those business users that say one thing but want another. Reacting to bugs can also become easier to manage due to the ability of smaller deployments, as you have the ability to release only the solution that has changed. As the development project is managed by you and not a third party software vendor, using a multi solution approach makes much more sense. 

Mixed Mode
Hopefully this won't confuse you further, but a mixed mode of the two could also be utilized  Whereby you use a multi solution approach during development and then merge and produce a single solution for production release.

Saturday, 28 September 2013

Installing CRM 2013

With the upcoming release of CRM 2013 and the current availability of the RC 1 build, thought I'd share the steps on how to get this installed.
Prerequisites
Windows 2008 Server x64 or Later
SQL Server 2008 x64 or Later


1. Launch the SetupServer.exe to start the install. Click Next

2. Here you can select the roles you want to install, for demonstration purposes I'm going to install all the roles on a single server. However it is strongly advised to separate roles across multiple computers to distribute processing load. Click Next

3. Select the "Create a new Deployment" option, then enter in the name of the SQL Server instance you want to use for this CRM 2013 deployment. Click Next

4. Select the OU you want to use for this CRM 2013 Deployment. Click Next

5. Specify the Service Accounts you want to use for each service listed. Click Next

6. Here you can decide if you want to install CRM to use the Default Website within IIS or create a new website with a specified port. Click Next

7. This is an optional step where you can specific the server name of the Email Router. If you plan to do this at a later stage, keep in mind that you will need to add the computer to the AD PrivUserGroup. Click Next

8. Enter in a unique name for the Database name, which will be used for the default CRM Organization name. Here you can also set the currency settings and SQL collation. Please note that the SQL collation cannot be changed later. Click Next

9. Enter in the URL to the SSRS report server. Click Next

10. Click Next

11. Select which option you want to use for Microsoft Updates and Click Next

12. The installer will perform the necessary system checks. You will notice a warning statement regarding Date encryption which is new to CRM 2013, this states: 


"Data encryption will be active after the install or upgrade. We strongly recommend that you copy the organization encryption key and store it in a safe place. For more information, see http://go.microsoft.com/fwlink/?LinkId=316366."

Click Next

13. Click Next

14. Confirm you are happy with all configuration settings and click Next

15. That's it, CRM 2013 is now installed successfully. Optionally you can install SSRS Reporting Extensions


Monday, 23 September 2013

CRM 2011 Installation Error - Setup failed to validate specified Reporting Services Report Server

When trying to install CRM 2011 in an environment where the SQL Server machine name has been changed, you may experience an error displayed below:
"Setup failed to validate specified Reporting Services Report Server"

You may have also experienced the issue The instance name must be the same as computer name

The  "Setup failed to validate specified Reporting Services Report Server" issue, is due to an incorrect server name being used by SSRS. 

1. To fix this, start the Reporting Server Configuration Manager and click on the Change Database option displayed below

2. Report Server Database Configuration Wizard

3. Click Next, you will see the server name being used

4. Correct the server name and use the Test Connection to confirm all is good

5. Select the Report Server Database

6. Click Next and wait for all tasks to complete

7. Click Finish and re-run the CRM Installer, now it should resolve the correct SSRS report server

Sunday, 22 September 2013

CRM 2011 Installation Error - The instance name must be the same as computer name

Recently when installing CRM 2011, I came across an error I haven't seen in sometime. 
The instance name must be the same as computer name.


The cause of this error, was due to the SQL Server Instance machine name being changed. More Importantly the server name change was done after the SQL server software had been installed.

Fortunately the steps to rectify this are pretty simple as follows:

1. Connect to the SQL Instance using Management Studio and identify the current name

2. Next we need to drop this server name as displayed

3. Now we need to add the correct server name

4. Finally Restart the SQL Service Services

That's it, now when you re-run the installer and perform the system checks, the error should not appear.


Wednesday, 11 September 2013

CRM 2011 - Add/Remove Team Members

Records within CRM 2011 can be owned by either a User or a Team. 
Using Teams within CRM 2011 are a great way of sharing records between users whom:
  • Are in different Business Units
  • Do not have the correct security role against their User record
  • Don't have ownership of the record(s) they want access too
However, the main benefit of Team ownership compared to User, is that ownership is shared by all members of the owning team, rather than a single user. Security Roles applied to that Team can elevate what a User can do when being a member.


An important part of maintaining this form of ownership, is to automate how members of a Team are added and removed, you may at times want to link certain UI actions to trigger these events. This can be done very easily from within a plugin as shown below:

  1. /* Add Users to Team */
  2. AddMembersTeamRequest addMembersTeamRequest = new AddMembersTeamRequest();
  3. addMembersTeamRequest.TeamId = Guid.Parse("831F6F02-6947-46BC-BDDF-6571075569A9");    //Team
  4. Guid[] arrMembers = new Guid[] {
  5.   new Guid("A4349C86-6475-43E6-BC1D-C3244115107C"),                                   //User 1
  6.   new Guid("8121CF3B-93B4-4907-9888-46FFAA11A169")                                    //User 2
  7. };
  8. addMembersTeamRequest.MemberIds = arrMembers;
  9. AddMembersTeamResponse addResponse = (AddMembersTeamResponse)ServiceProxy.Execute(addMembersTeamRequest);
  10.  
  11. /* Remove Users from Team */
  12. RemoveMembersTeamRequest removeMembersTeamRequest = new RemoveMembersTeamRequest();
  13. removeMembersTeamRequest.TeamId = Guid.Parse("831F6F02-6947-46BC-BDDF-6571075569A9"); //Team
  14. arrMembers = new Guid[] {
  15.   new Guid("A4349C86-6475-43E6-BC1D-C3244115107C"),                                   //User 1
  16.   new Guid("8121CF3B-93B4-4907-9888-46FFAA11A169")                                    //User 2
  17. };
  18. removeMembersTeamRequest.MemberIds = arrMembers;
  19. RemoveMembersTeamResponse removeResponse = (RemoveMembersTeamResponse)ServiceProxy.Execute(removeMembersTeamRequest);

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: ...