Posted on 28. September 2011

Generate Early Bound OptionSet enums

The latest release of the CRM 2011 SDK includes an extension to the CrmSvcUtil to generate OptionSet enumerations. Previously, the tool only generated enums for the StateCode attributes, leaving it as a manual task to create your own enums for any OptionSet values you needed.

Using the extension has never been simpler:

  1. Using Visual Studio 2010, compile the project found at:
  2. Edit the 'generateoptionsets.bat' file in the bin\Debug folder, replacing the /url: parameter with the url of your own CRM server.
  3. Double click the 'generateoptionsets.bat', and wait…
  4. You'll see an 'OptionSets.cs' file created in the Debug folder.

You simply need to include this file in any of your projects and use when setting OptionSet values, being sure to cast as (int).


Posted on 22. September 2011

Update Rollup 4 Released!

Here it is!

The release schedule for the next two are:

  • Update Rollup 5 will be delivered earlier than the 8-week cycle and is scheduled to release at the end of October 2011.
  • Update Rollup 6 will be delivered on its predefined schedule, 16 weeks after Update Rollup 4, which puts the delivery in January 2012.

Some great fixes in UR4 though. I'm particularly pleased about:

  • If you register a plug-in assembly against an incident entity in the post-operation stage, the plug-in assembly is unexpectedly executed outside the transaction. 
  • Assume that you create a task in Outlook and track the task in Microsoft Dynamics CRM 2011. When you synchronize the task with Microsoft Dynamics CRM, the due date for the task is changed incorrectly to a previous due date. 
  • When you add the Actual End field to an email message form and then set the format to Date and Time, the time value is displayed in UTC format instead of your local time zone. 
  • When you click Audit History in the Microsoft Dynamics CRM 2011 Web client, you receive the following error message: An unexpected error occurred.

The incident transaction issue was causing serious problems for customers with Plugins that needed to rollback the 'create' transaction. What happened prior to UR4 is that the transaction didn't rollback if your plugin threw an exception, even though the form thought that the record hadn't be saved. When you then tried to save again, a 'duplicate record' exception was thrown.



Posted on 22. September 2011

AddItem & RemoveItem Plugin Message‘gotchas’

When registering a Plug-In Step on the 'AddItem' and 'RemoveItem' messages I've found a couple of things to watch out for.

1. Missing InputParameters

When registering on Campaign Activity in response to adding a Marketing List, the InputParameters collection on the 'AddItem' step should contain the following:

  • EntityName = 'List' (String)
  • CampaignActivityId = <Id of the activity the list is being added to> (Guid)
  • ItemId = <Id of the list being added> (Guid)

However, when registering against the 'RemoveItem' message, watch out for the fact the 'EntityName' parameter is missing.

2. AddItem message fired even if item already is added.

When registering on Campaign Activity in response to adding a Marketing List, the AddItem message will fire each time the user selects 'Add from Campaign' even if the list already is associated with the Campaign Activity.

For this reason, you will need to check that the item is not already present to prevent your plugin from executing even when the item isn't actually being added:


bool listAllreadyAdded = (from l in serviceContext.CreateQuery<List>()
                                         join a in serviceContext.CreateQuery<CampaignActivityItem>()
                                           on l.ListId equals a.ItemId
                                         where a.CampaignActivityId.Id == activityId
                                         select true


Posted on 10. September 2011

Easier User Guides

If you've ever written user guides for a Microsoft Dynamics CRM 2011 custom solution, you'll know writers block all too well; staring at a blank Word Document waiting for inspiration on where to start. The Dynamics CRM 2011 User Guide in Microsoft Word Format is just that place – with a structured table of contents that makes it easy to add in your custom functionality in amongst the standard features.

Download it now:

Posted on 8. September 2011

Calling a function in an HTML Web Resource from another JavaScript Web Resource


If you have a field value on an entity form that an Html Web Resource is dependant on, you might have the following in your onload event of the Html Web Resource:

var crmForm = window.parent.Xrm.Page;
var lookup = crmForm.getAttribute("customerid").getValue();
if (lookup != null) customerid = lookup[0].id;


If so, will need to ensure that when this value changes, you update the values displayed on the html web resource. Rather than simply re-loading the web resource, it's going to be better for the user if you create a function to update the values without it blanking and re-loading.

You can do this by implementing a function in your html web resource and then calling it from the onchange event of the dependent field:


Hope this helps.