The requirement is:
When a user clicks on a form's tab in a Crm detail form, a record needs to be entered into an (Oracle) database. In case of success show a webpage from a particular url (to an application that reacts to the data in the record), in case of failure show a message.
The most elegant way to react to the onclick event of the Tab, in my opinion is to attach to this event in Javascript, ofcourse it is important not to interfere with the attached handler that is already present and takes care of the showing/hiding of the tab's content.

First I took the IE Developer Toolbar, and with the 'Find' > 'Select Element by Click' functionality, I reduced the Tab's id: 'tab4Tab'.
In the Onload handler, of the Form.Properties I added this:

   1:  var tabVar= crmForm.all.tab4Tab; 
   2:  if(typeof(tabVar) != "undefined" && tabVar != null) 
   3:  { 
   4:       crmForm.all.tab4Tab.attachEvent('onclick',insertRecordAndRedirect, false)
   5:  } 
Listing 1

First the tab object with id: 'tab4Tab' is put into a variable called 'tabVar'.
When this variable is not null and not 'undefined', the function called: 'insertRecordAndRedirect' is attached to the onclick of the 'crmForm.all.tab4Tab' object.

So the function 'insertRecordAndRedirect' is called, the moment the Tab with id: 'tab4Tab' is clicked.
This function is also inserted in the Onload handler, of the Form.Properties (like listing 1):

   1:  function insertRecordAndRedirect()
   2:  {
   3:      var id = crmForm.objectId.value;
   4:      document.all.IFRAME_CrmTab.src =''+id;
   5:  }
Listing 2

The function reads the value (a Guid) from the objectId property of the crmForm object (the UniqueIdentifier of the database record, from which the details are shown in the form). The aspx page that is called takes care of the inserting of the record into the database, using the provided querystring parameter.

In my case, this works really good, and it also solved an issue I had with GoogleMaps and LiveMaps. Because the tabs on which I put the maps are invisible when the form loads, the maps do not seem to know how big they are.

The result is:

  • In the case of GoogleMaps that the center of the map (the chosen spot on the map is centered) always was on (0,0). Left=0, top=0. When using the 'onclick of the Tab' approach, the map is loaded when the tab is clicked, so the map is visible and the map is centered as intended.
  • In the case of LiveMaps, only the right, lower corner of the map was visible in the left, upper corner of the iframe. But when using the 'onclick of the Tab' approach, the map is loaded when the tab is clicked and the map is completely visible and centered as intended.

Henry Cordes
My thoughts exactly...

CRM 4.0 Workflows don't start

Published 01/04/2008 by Henry in CRM

In CRM 4.0 the MS CRM Workflow Service is not available anymore. CRM 4.0 has one Async Service the 'Microsoft CRM Asynchronous Processing Service'. The Microsoft CRM Asynchronous Processing Service takes care of all asynchronous processess that run within CRM like Workflow and Plugins (former Callouts). 

The Microsoft Dynamics CRM system architecture can be divided into 3 major components: the core system, which features the event execution pipeline, the database component, which hosts the asynchronous queue, and the asynchronous service. One benefit of the scalable architecture of Microsoft Dynamics CRM is that the asynchronous service can be hosted on servers other than the Microsoft Dynamics CRM server. This distributed processing capability can result in improved performance of Microsoft Dynamics CRM.

At a client I work on a CRM 4.0 system, my help was asked when updated workflows (from CRM 3.0 to CRM 4.0) that worked in CRM 3.0 did not work.
I soon came to the conclusion that the workflows did not even started. First I tried changing the executing identity on the service, which did not change anything.

After googling I found that lots of people had this problem and that the problem always was related to the MS CRM Website running with a hostheader, or second ip-address.
After trying out several different options my conclusion is that: 

CRM 4.0 needs to run without a hostheader and with the IP-address option 'All unassigned' chosen.
So you cannot use another IP-address and you cannot use hostheaders (if you want the workflow to function)!

I already found out that the CrmDiscoveryService Web service under the hood uses the machinename to connect to the CRMService and the MetadataService, when I tried to register a Plugin using the PluginRegistration Tool.
Which in itself is remarkable IMHO, the reason for a DiscoveryService is, I think, to decouple these services, which is rather hard if you can only connect using the machinename.

Anyway, if you got this issue make sure you use the following settings (the TCP port is not important in this case, you can use 5555 or 80 or another port):

IIS Website settings for MS CRM 4.0 website, assing no ipaddress and do not use hostheader
All unassigned without hostheader

Henry Cordes
My thoughts exactly...

CRM 4.0 Plug-in Developer Tool Extended

Published 14/02/2008 by Henry in CRM

I am in the process of developing CRM 4.0 Plugins. This is very different from the formerly known Callouts.
One of the differences is that these assemblies can be deployed to the database, they need to be registered inside CRM.  When plug-ins are registered in Microsoft Dynamics CRM, they become part of the primary operation of the CRM system. Which is different from CRM 3.0 also.
The object model is different, now the assembly must implement the IPlugin interface that lives inside the Microsoft.Crm.Sdk assebmly that comes witk the CRM 4.0 SDK.

Registering the Plugin is done by using API's provided by the CRM 4.0 SDK. The SDK provides the (C#) sourcecode that compiles into a Windows Forms Application that calls these API's to register a Plugin.
With this tool you can register the plug-in on disk or in the database. Here a screenshot from the mainform of that application the 'Plugin Registration Tool for CRM 4.0': 

CRM 4.0 Plugin Developer Tool
Plugin Registration Tool for CRM 4.0

While struggling with this process, I stumbled on the next tool:

This tool is more complete than the 'Plugin Registration Tool for CRM 4.0' provided as sample code with the SDK. It is developed by the Microsoft Dynamic CRM Team.

New and re-engineered PluginRegistration tool
New and re-engineered PluginRegistration tool

The team addressed 3 core scenarios with this tool.

  1. Developer Scenario:
    An ISV creates a plug-in and registers it on Contact Create as PreCallout (Aka BeforeMainOperation Plug-in). He can then debug the plug-in by registering on Disk. Once the errors are fixed, he can then update the pluginassembly to be uploaded to the database.
  2. Deployment Scenario:
    An ISV builds few plug-ins and registers on multiples steps. Images are registered on few of them. He tests them in the Dev environment but would like to port the registrations to a different organization. PluginRegistration tool supports Export and Import of the solution xml to solve this scenario.
  3. Admin Console:
    Couple of ISV installs their plug-ins on a Customer Organization. Admin at the Customer side saw some problems with “Contact Create” action. He would like to know what plug-in are fired and what the pipeline is for the “Contact – Create”. He then finds the trouble causing plug-in and disables it. So it is all about troubleshooting. PluginRegistration tool solves this problem by allowing Enable/Disable/Unregister operations on steps, plug-in.

The "New and re-engineered PluginRegistration tool" as the team calls it themselves on their blog can be found on here:

Henry Cordes
My thoughts exactly....

Adding new custom entity to CRM 3.0 fails

Published 16/01/2008 by Henry in CRM

While we went in production a few requirements were added to our CRM 3.0 project. The last thing we did before going into production was adding and removing roles and teams.

All system roles accept System Administrator where removed, only custom roles where needed, als teams where added. Because of the new features a new (custom) entity needed to be created. When I saved it the following message appeared:
"An error has occurred. For more information, contact your administrator" (talking about a meaningfull error message!).
While I tried to solve this problem I found out Microsoft has a hotfix available for this problem ( This hotfix can only be obtained through a support ticket from MS Support. In this blogpost is stated that the deletion of the 'System Customizer Role' does the damage.

It has a reference to this KB Article (Microsoft KB article 934690):
When a custom entity is created, Microsoft Dynamics CRM automatically grants the System Customizer role access to the new entity. If you delete or edit the System Customizer role, you receive the error message that is mentioned in the "Symptoms" section.
The blogpost states it appears that when creating a custom entity CRM checks if the 'System Customizer' role is present (at least the if a role with a RoleID equal to the Guid this role had when CRM was installed). Also just manually recreating a "System Customizer" role does not fix the problem.

The solutions present at that moment in time:

  • MS Hotfix
  • Fresh install of CRM with data migration (back up CRM, uninstall CRM, install CRM fresh and then migrate all of your data from the back up into the new system)

Now I really wanted to know what's going on, so I hooked up a trace with SQL Server's profiler. A lot of stored proc calls are made, but just before the first ROLLBACK this dynamic SQL was executed:

   1:  exec sp_executesql N ' select role.RoleId as ''roleid'',role.BusinessUnitId as ''businessunitid''
   2:  from Role as role inner join BusinessUnit as rolebusinessunitid
   3:  on (role.BusinessUnitId = rolebusinessunitid.BusinessUnitId) and rolebusinessunitid.DeletionStateCode in (0)
   4:  and (rolebusinessunitid.ParentBusinessUnitId is null )
   5:  inner join SystemUser as businessunitorganizationid
   6:  on (rolebusinessunitid.OrganizationId = businessunitorganizationid.OrganizationId)
   7:  and businessunitorganizationid.DeletionStateCode in (0)
   8:  and (businessunitorganizationid.SystemUserId = @P1)
   9:  where role.DeletionStateCode in (0)
  10:  and (role.RoleTemplateId = @P2)',N'@P1 uniqueidentifier,
  11:  @P2 uniqueidentifier','X1X1X1X1-Q1Q1-Q1Q1-Q1Q1-X1X1X1X1X1X1','Z2Z2Z2Z2-Y2Y2-Y2Y2-Y2Y2-Z2Z2Z2Z2Z2Z2'
Listing 1

When I ran it in the  SQL Server Manager's Query Window an empty row was returned. 
The following part of the SQL is interesting in this case:

(role.RoleTemplateId = @P2) 
Listing 2

Maybe this could be the Guid that is absent. When we look inside the RoleTemplateBase table we see that all system roles exist in this table, even though they do not exist as roles in this CRM implementation anymore.
When a new entity is created CRM checks to see if the executing user is a member of any role that has a relation to the template with the RoleTemplateId of the 'System Customizer' role template. This to me is strange behavior, specially because the RoleTemplateBase table has no field or relation to the settings of a Role, the only fields it has are:

  • RoleTemplateID;
  • Name;
  • Version;
  • Upgrade.

'RoleTemplateBase' table of the '<organization>_MSCRM' database  
'RoleTemplateBase' table of the '<organization>_MSCRM' database

I used the MS CRM Role Utility to export the System Customizer role to a xml file from a shadow VPC that still contained the role. Als with the MS CRM Role Utility I imported the role into CRM. Here is a link: Systeemaanpasser.xml (31,23 kb) to the xml containing the role (NOTE this is a Dutch CRM installation!, I will try to post an English version of the 'System Customizer' role also).
So the role is in  the system again, now I ran a somewhat customized version of the Dynamic SQL, so it is not dynamic anymore. Figuring when it returns a row this error will be gone.


   1:  select role.RoleId as 'roleid',role.BusinessUnitId as 'businessunitid' 
   2:  from Role as role 
   3:  inner join BusinessUnit as rolebusinessunitid 
   4:  on (role.BusinessUnitId = rolebusinessunitid.BusinessUnitId) 
   5:  and rolebusinessunitid.DeletionStateCode in (0) 
   6:  and (rolebusinessunitid.ParentBusinessUnitId is null ) 
   7:  inner join SystemUser as businessunitorganizationid 
   8:  on (rolebusinessunitid.OrganizationId = businessunitorganizationid.OrganizationId) 
   9:  and businessunitorganizationid.DeletionStateCode in (0)  
  10:  and (businessunitorganizationid.SystemUserId = 'X1X1X1X1-Q1Q1-Q1Q1-Q1Q1-X1X1X1X1X1X1')  
  11:  where role.DeletionStateCode in (0)  
  12:  and (role.RoleTemplateId = 'Z2Z2Z2Z2-Y2Y2-Y2Y2-Y2Y2-Z2Z2Z2Z2Z2Z2') 
Listing 3

I ran the query and it returned nothing:

Empty result of query
Empty result

I opened the 'RoleTemplateBase' table, selected the row containing the 'System Customizer' role and copied the Guid in the 'RoleTemplateID' field to the clipboard.
Than I opened the Role view (remember 'Select ... from Role as role') and searched for the row containing the newly added 'System Customizer' role.

Records in 'Role' view 
Records in 'Role' view

In this row I pasted the Guid (I earlier had copied to the clipboard) into the field 'TemplateRoleID' and saved it.
Than I ran the query again, but now it returned a row:

Result: "one row"
Result: "one row"

I tried to add a new custom entity into CRM and guess what it worked again!
So the advice I read in a few CRM related blogposts to never remove system roles (specially the 'System Customizer' role) is repeated here in this post.

Henry Cordes
My thoughts exactly...

CRM 4.0 SDK available

Published 05/01/2008 by Henry in CRM

Well, Titan  (MS CRM 4.0) production release is available  (as 90 day trial)  for download.
Today I learned that the CRM 4.0 SDK is available also, it can be downloaded here.

The CRM SDK does help a lot when customizing a CRM implementation. It has documentation, references, best practices and code samples. I really am happy that it is out and available for us.
I will be involved in a migration project from a CRM 3.0 to CRM 4.0 so maybe will post some more on CRM 4.0 in the near future.

The CRM 4.0 90 day trial versions can be downloaded here.
There are three versions available:

  • Workgroup
  • Professional
  • Enterprise

Within the 90 day trial you can upgrade to a licensed product anytime, you just enter a valid license-key.
After the 90 day period, no warning is given, the product just stops working. When a valid license-key is sentered, the  product will normally continue to work as a licensed product.

Henry Cordes
My thoughts exactly...