CRM 2015 – plugin deployment options

I was asked this question today

Do I need to restart IIS (Internet Information Services) after I have deployed my plugin?

My initial quick answer was no but then I was curious why they asked me the question? This is what I refer to as a suspicious question.  Often the question people ask, isn’t the real question they want to ask, a bit like when my 3 year old daughter asks.

“What’s that chocolate bar doing on the table Daddy?”

The real question

“Daddy I want to open and eat that delicious looking chocolate bar”

This picture isn’t my child but it’s a fits the text above

Plugin storage options

There are three plugin storage options

  • Database
  • Disk
  • GAC

deployment options

The options are fairly self explanatory.  (plugin.dll is your custom plugin assm)

  • Database = Plugin.dll uploaded into the database
  • Disk = The Plugin.dll is saved on the CRM Servers hard disk
  • GAC = The plugin.dll is loaded into the GAC on the CRM Server.

If you don’t know what the GAC is it’s the Global Assembly Cache.  It’s a common area on a computer to store the DLL’s which is C:\Windows\assembly.   This discussion has a good definition – What is the GAC in .NET

As always Start with the SDK, which has a good article on the subject

Register and Deploy Plug-Ins

Default Option

The default option should be store your plugin on the database and to be honest I can’t think of any reason why you would store you plugin not in the database.  Microsoft STRONGLY agrees with me (excellent, I like it when Microsoft does that)

We strongly recommend that you store your production-ready plug-ins in the Microsoft Dynamics CRM database, instead of on-disk.

The advantages of deploying your plugin to the database our

  1. The plugin is backed up when the database is backed up
  2. For multiple server configurations you only need to deploy once to the database and not individually to each CRM server.
  3. Plugins in the database can be added to solutions, Disk, GAC plugins cannot
  4. Plugins deployed to the GAC or Disk will need an IISRESET to refresh, plugins deployed in the database do not.
  5. Sandboxed and CRM Online plugins have to be deployed in the database

If you want to understand what deploying to the Sandbox is read my blog post Understanding Plugin sandbox mode

I have experienced a CRM deployment where common code used by the plugins was held in a separate DLL which was stored in the GAC of the CRM servers.  The preproduction environment had 8 CRM Servers and the Production environment had 11 CRM servers.  It was a tedious job to install the DLL on every server, restart the ISS server and CRM async services.

I cannot think of any advantages to installing CRM plugins on the server or in the GAC so my advice is never to do it.

Some people might think you need to install the plugin.dll on the CRM server to enable remote debugging but this isn’t true, you can install the plugin.dll in the database and put the pbd file in the the folder C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly.  Microsoft gives you this tip on the Debug a plugin page

It is possible to debug a database deployed plug-in. The compiled plug-in assembly’s symbol file (.pdb) must be copied to the server’s <crm-root>\Server\bin\assembly folder and Internet Information Services (IIS) must then be restarted. After debugging has been completed, you must remove the symbol file and reset IIS to prevent the process that was executing the plug-in from consuming additional memory.

Personally I prefer to use the plugin registration tool to debug plugins because this can be done a CRM Developers individual machine.  When people remote debug on the CRM server this can sometimes slow, stop the CRM Async services from running and processing other plugins.

Basically it’s not good CRM developer etiquette to stop other developers using the system because you need to debug a plugin (although sometimes need must).

A better system is to write unit tests to test the logic of your code in isolation

CRM MVP Gonzalo Ruiz has written a great article on the benefits of registering your plugin to the CRM database.

6 Great Reasons to Register your Plugins in Database Instead of Disk/GAC

Point number 4 is interesting

4. Disk assemblies will not support multiple versions

I never realised (or yet needed/wanted to use) you can store multiple versions of an assembly.

I found one small reason for deploying to disk, highlight by this blog by David Jennaway, where he mentions if you plugins have dependant dll’s you can put them in the same directory as the plugin, in a similar way the plugin registration tool has the CRM SDK dll’s in the same directory but this isn’t much of a reason.

What can you restart and how does it effect plugins

There are a few things which you can restart which can affect your CRM plugins.  I will state plugins deployed to the CRM database do not need any of these restarted, which is another good reason to deploy your plugins to the CRM database.

  • IIS Server
  • Recycle CRM App pool
  • Restart CRM Services

You do sometimes need to check the IIS Server or CRM services if your CRM isn’t working, for more detail check out the article Microsoft Dynamics CRM not working? check these common causes

IIS Server

Lots of CRM developers I have met do an IIS Reset and Async CRM Services restart when ever they deploy a plugin, even when the plugin is deployed in the database and they didn’t need to.  The reason they did this was because the CRM developer who helped them learn CRM did it, so now they do it.

First lets understand what doing an IIS Reset does.  When you type IISRESET into the cmd line or go to the IIS server and click restart.  The first thing you should do is warn the users you are about to take down CRM and all other websites and web services hosted in IIS.  The key point is it restarts everything on the IIS server and not just CRM, make sure you want to restart everything.

IISRESET restarts these services, it’s the same as stopping and then starting the three services below according to this post 

  • IIS Admin Service
  • Windows Process Activation
  • World Wide Web Publishing

This discussion has an excellent summary what IISReset does What does an IISReset do?

IISReset stops and restarts the entire web server (including non-ASP.NET apps)
Recycling an app pool will only affect applications running in that app pool.
Editing the web.config in a web application only affects that web application (recycles just that app).
Editing the machine.config on the machine will recycle all app pools running.

IIS will monitor the /bin directory of your application. Whenever a change is detected in those dlls, it will recycle the app and re-load those new dlls. It also monitors the web.config & machine.config in the same way and performs the same action for the applicable apps.

useful tip – If you are doing an IISReset via command line then it’s a good to do

IISReset /noforce

This will gracefully close down IIS rather than IISReset and wait for processes to finish.  IISReset will abruptly close down IIS which could leave processes half way through updating the CRM database! which is something you want to avoid.

This discussion highlights an area where you need to recycle the app pool

Do we really need IIS Reset and Async Services restart when we depoly plug-in or custom workflow – CRM 2011

There is one other scenario where you need to recycle the CrmAppPool application pool. If you modify the parameters that are available for a Custom Workflow Activity, then CRM will not make any new parameters available when editing the workflow until after recycling the application pool.

Recycling the CRM app pool is a lot less disruptive than restarting the whole server.

I couldn’t find any need to do an IIS reset for database stored plugins, I think you would need to recycle the app pools to if you your plugins are stored in the GAC or Disk.

CRM Services

You have a number of choices when deploying plugins which effects what CRM process runs the plugin code.  Here are the CRM services

CRM services

Isolation mode

  • Sandboxed
  • none

If you choose Sandboxed the plugin code will be run in CRM Sandboxed Processing services, this service is sandboxed, if the plugin tries to modify or access external dll’s, certain system resources an error will be thrown.

if you choose none it gets run by the core CRM system in the event execution pipeline if it Synchronous, if it’s asynchronous it gets run by the CRM async service

CRM Async services

I have written before about CRM 2013 – Understanding SystemJobs and Async Plugins.

If you look at the msdn article – Event execution pipeline, this picture shows you the various parts of CRM

Synchronus plugins runs straight away and the CRM form will hang until the plugin has successfully run.  Looking at the architecture above you can see synchronus plugins get run in by the core CRM system inside the database transaction.

Async Plugins get run after the  Plugin execution pipeline has finished and go into the Async Queue Manager and get run when CRM has free resources.  Researching this topic today I found Microsoft has quite a large section on Asynchronous services in CRM, which I have never read until today

Asynchronous service in Microsoft Dynamics CRM

This article Asynchronous service architecture is mentions this

The asynchronous service features a managed queue for the execution of asynchronous registered plug-ins, workflows, and operations such as bulk mail, bulk import, and campaign activity propagation. These operations are registered with the asynchronous service and executed periodically when the service processes its queue. The asynchronous service can be hosted on a server other that the server running Microsoft Dynamics CRM.

The reason I mention the Async service is because there is a small piece of best practise I had not considered or heard before tucked in the

You should stop the asynchronous service before you unregister a plug-in that was registered to execute asynchronously. Stopping the service prevents a situation where an asynchronous registered plug-in has been queued for execution but for which there is no plug-in assembly currently registered. For example, consider the situation in which a plug-in has been registered to execute asynchronously and the related event has fired. After the asynchronous operation has been queued by the queue manager, you then unregister (delete) the plug-in assembly from the Microsoft Dynamics CRM database. In this case, an error occurs when the asynchronous service tries to execute the queued asynchronous operation but the plug-in assembly no longer exists.

So if you have Async plugins then it’s good practise to restart the CRM Async service when you unregistered an async plugin.  This will avoid a plugin being queued which has been unregistered.

Finally I will leave you with the my post on common plugin errors and isolation mode

CRM 2011/2013 – Common Plugin Errors and Isolation Mode

Back to the question

I forgot about the question. The answer is no the developer won’t have to do an IISReset if the plugins are deployed to the database, which they were.

It’s been interesting researching this topic and I have learnt a bit more about the CRM architecture


Hosk’s Top CRM Articles of the week – 26th June

Article of the week

CRMDeveloperExtensions from Jason Lattimer

I just want to let people know, Jason Lattimer has uploaded his CRM Developer extensions to Github, so download it and have a play.

Top Ten Secrets to a Successful CRM Deployment: Part One–People

Great article from Leon Tribe on the secrets to a successful CRM deployment.  There are lots of pieces, lots of people, lots of customizations, lots of data.  You need to herd them all in the direction of success

Best of the rest

CRM 2015 – CRM developers should think in Entities

Hosk blog post on why CRM developers should view everything as entities.

Pass Plugin Context Message C# Exception to Form Script (Javascript) during CRM Ribbon Calling Action

How to catch plugin errors in your javascript

Compare This Year to Last Year with a Dynamics CRM chart

The CRM Chart master gives another chart master class

#IoT2CRM: The gateway revised

I enjoyed reading this article, an interesting piece of using Gateways and thinking about the data you use in CRM projects

CRM 2013 – How to stop these annoying things in Microsoft Dynamics CRM

There are a few annoying things which feels good to squash and stop.  Liking pending emails, annoying welcome woman, incorrect format, send report pop up etc.

Rolling in a New Feature to Stay Updated in Dynamics CRM

I like the quirky way you can use rollup fields and it’s daily rolling up functionality.  It would be good if CRM had schedule functionality

Hide / Show Export to Excel button for specific Entity / Specific View

How to hide the export to excel button for individual entities

CRM 2015 – how to find Statecode value

A quick way to find a statecode value

How to Add Parameters to a Fetch Based Report

A good blog showing you how to add parameters to fetch based reports.

The Workflow Executor for CRM2011, CRM2013 and CRM2015

CRM systems can have lots of workflows in various stages.  This free tools lets you set the status for many workflows at once.

Tip #418: 3 ways to find the blocking attribute

3 ways to find an attribute

Did you know

Explanation of some of the default fields


Joel Spolsky : The law of leaky abstractions

Three great articles on debugging

The Startling Cost of Losing a Developer

Think twice before logging

34 CSS Puns That’ll Make You Laugh, Even If You Aren’t A Web Designer

Continuous Delivery Among the Donkeys

How peer review leads to quality code


Shhh, Google Chrome is listening

8 Things Every Person Should Do Before 8 A.M.

Windows 10 inside story

Probability Trumps Predictions When Making Forecasts

How It’s Made Series: Beats By Dre

Exclusive: Satya Nadella reveals Microsoft’s new mission statement, sees ‘tough choices’ ahead

Hearthstone: how a game developer turned 30m people into card geeks

Previous top picks

Hosk’s Top CRM Articles of the week – 19th June

Useful Hosk Links

Hosk list Of CRM 2013 Tools

A list and review of CRM 2013 tools, this will probably work in CRM 2015 as well

Hosk’s CRM Developer Articles

A collection of my favourite CRM Developer articles I have written

MB2-703 – CRM 2013 Customization and Configuration Certification Information

All the CRM 2013 content to help you pass the exam

HoskWisdom – Hosk Developer Quotes

 Words of Wisdom from the Hosk.  I have written over 900 articles, surely I should have said a few memorable things

CRM 2013 – How to stop these annoying things in Microsoft Dynamics CRM

There are a few common and very annoying problems that annoy me with CRM, so I have decided to group them together in this blog so I can easily and quickly find how to stop them.

Disable Send Report to Microsoft pop up

I personally have always wondered what Microsoft does with all those error reports it asks people to send!

You might be tired of clicking on these message and you probably don’t want your end users to see this popup.

Good news – Luckily Microsoft have added a setting we can turn off

Bad news – it’s hidden in a place where no one would dream of looking

If you want to stop this message, you need to go to

Settings –> Administration –> Privacy Preferences –> tick box and select Never send

privacy settings

Users get created with the wrong format

This is a common and annoying problem for UK CRM Developers.  You create a new organisation which as the default English (United States).  This is clearly no good for UK users because the Americans have got their months and days mixed, currency dollars etc.

All the users you add will be given the same Format settings as the default.

Once a user is created the only way to change their format settings is to go into their personal options and change the format settings.

The way to avoid setting users with English (United States) is to change the Current Format in the System Settings to English (United Kingdom) and then create your users.

Stop the Annoying Welcome Woman

To do this you have to add a registry key.  I found the instructions on the awesome power object blog How to Disable the CRM 2013 Welcome Screen

On the CRM server in open Regedit


Add a new DWORD (32-bit) and call it DisableNavTour

Disable Hello woman

Annoying outlook download message

Microsoft is always trying to persuade people to download Outlook, if you have got annoyed at this message you can turn it off by flicking a switch in System Settings

Outlook message turn off

Get rid of annoying pending email warning message

The annoying pending email message has plagued me a number of times.  There are two ways to get rid of it.

1. Delete the pending emails, instructions here

2. Modify CRM Server registry setting DisablePendingEmailReminder to 1.  Instructions in this blog

CRM 2013 Navigation is slow and tricky

Quite how Microsoft made CRM 2013 slower and more difficult to navigate than CRM 2011 is a mystery but it was probably a decision they made whilst banishing the Start menu from Windows 8.

I have talked about it in this blog – Good CRM design should not make users think

You have a couple of good options

CRM 2013 One Click solution

Use these Bookmarks to help speed your navigation

CRM Navigation Hacking with Bookmarks

Trusted Sites

This isn’t a problem but something you need to remember when setting up CRM for customers you need to make sure you add CRM to IE’s trusted sites

How to Add CRM to Trusted Sites

CRM is acting weird, option sets don’t work properly

If you are using IE, trying playing with compatibility mode settings on your browser

Configuring Settings for IE 10 and CRM 2011

The article only mentions CRM 2011 and I can’t remember if I had these problems in CRM 2013 but I thought I would put it here.

Any more?

If you have any more annoying things in CRM please add them in the comments

CRM 2015 – CRM developers should think in Entities

The humble Entity is one of core building blocks of CRM and CRM development.

  • CRM developers need to view the world as entities
  • You need to translate users work items to entities
  • Understand out of the box entities and custom entities

When CRM developers look at things they should see things in entities like the matrix picture.

When a customer tells you the requirements you should be thinking about it in entities

You are an entity called CRM Developer!

What is an Entity

Entities do a lot in CRM, to understand what they are and what they do I think it helps to view them in different ways


Entities are used to model the business data of the customer to accompany the out of the box entities which exist in the default CRM system (account, task, contact, business unit)

CRM Database point of view

  • Every entity in CRM is a table in the CRM database.
  • Every field on an entity is a column on the entity table.

CRM Dev point of view

Most entities have at least one form in CRM.

Customizations are organised (to some extent around entities) in your solutions


CRM Developer Plugins

Plugins are triggered by actions on Entities (you can add multiple triggers on a plugin).  The messages (read actions on an entity) aer

  • Create
  • Update
  • Delete
  • Retrieve
  • Retrieve Multiple
  • Assign
  • Share
  • Associate
  • Dissociate
  • Set State

Entity Status

Entities have a status and status reason.  These values can be used to drive the entity through a process/life cycle.  To learn more about Status and Status reason read the blogs below

CRM 2013 – Understanding Status and Status Reason – think before deleting them

CRM 2015 – how to find Statecode value


Security roles set access rights on entities – Create, Read, Write, Delete, Append, Append To, Assign, Share.

Entities can be owned by users/teams and these provide access levels such as none, user, business unit, child business unit, organisational.


Start with the CRM SDK

When learning about topics in CRM it’s good policy to start with the CRM SDK and find the truth about entities, find out what properties and methods entities have.  When I use the term CRM SDK I mean the CRM SDK documentation

Development for Microsoft Dynamics CRM Online and on-premises (CRM SDK)

You could also look at the CRM Developer Website, which I wrote a blog about recently

CRM Developer Centre gets updated and it looks good



What properties/members do you get with the Entity

Entity Properties

The Entity has a number of properties but here are the keys ones


The attributes parameter holds a collection of all the fields in an Entity.  The atrributes collection works by holding fields which have a value.  If a field is null it isn’t included in the attributes collection (when you call from plugins).

You often need to check for a value in the Attributes collection using the contains method


This will create lots of if statements with contains, if true retrieve the attribute type code.  You can work around this by using Entity.GetAttributeValue which will get the value if the field exists in the Attributes collection or return the default value for simple variables or null for complex variables.  Read more about it using the link below

CRM 2013 – using Entity.GetAttributeValue instead of Entity.Contains

Each Entity has it’s own individual name stored as a string.  The logical name is useful because sometimes in the code you will need to know what type of entity it is e.g.

task, account, phonecall, contact.

The LogicalName can be useful if you have plugin code which is triggered on a number of different entities.


The all important Id of the entity record.  This holds the Guid.  This is important because when you retrieve any information you can use this ID to retrieve the individual Entity record and ask for particular fields of interest.


Gets the state of the entity, useful

Entity Abstraction and Early binding

Good practise for CRM developers is to use Early binding which will create an Entities file and allow you to create Account, Contact, Task records.

Early binding strongly types the field values for an entity.  These values are the same fields you would find in the attributes collection on the Entity object.

  • What are the benefits of early binding
  • Readability
  • moving type errors into compile time and not run time (e.g. compile time = developers, runtime = testing or users)
  • reduce syntax errors

The easy way to make your Entities file is to use the CRM Early bound generator

CRM 2013 Tool – CRM Early Bound Generator

Whilst you are there don’t forget to make your optionset enums

CRM 2013 – Create Enumerations for option sets

What has the Entity got to do with Abstraction?

When you are using early bound classes in your CRM code you are then extending Entity object with the new early bound classes

Entity –> Account, Contact, Task, etc

Using Entity can be useful when creating common functions because all your early bound classes inherit from Entity.

The code below checks the entity (which is an Entity object) to check the name.  The code in the example could be either a Task or PhoneCall.  The Complete activity either sets a task to completed or a phonecall to made.

            if (entity.LogicalName.Equals(Task.EntityLogicalName))
            else if (entity.LogicalName.Equals(PhoneCall.EntityLogicalName))

It’s useful to remember all early bound entities inherit from Entity.

EntityReference – Entity’s little brother

The EntityReference object in CRM is a lookup to an Entity object.  An EntityReference has LogicalName and Id (guid) of the entity.

When ever you see a lookup in a CRM form you know this is an EntityReference with just enough detail for you to retrieve the Entity object.

There is a good code tip is you can get an Entity Reference from an Entity object

Hosk CRM Dev Tip – Get EntityReference from Entity

EntityReference entRef = entity.ToEntityReference();

When creating new lookups on your forms, it’s best practise to put ID on the end of the field name, so CRM developers can easily find the lookups

Hosk CRM Dev Tip – add ID suffix to lookup fields


CRM 2015 – how to find Statecode value

Someone asked me how to find the StateCode value on a custom entity today, so the first thing I did was to search the Hosk CRM Blog.

A lot of people get confused between Status Reason and State code, if you do then read this blog post

CRM 2013 – Understanding Status and Status Reason – think before deleting them

quick guide

  • StateCode = Status
    • controls if the record is active/inactive
  • StatusCode = Status Reason
    • Status reason is linked to the state and gives the ability to different status reasons to a status.

CRM Developers point of view

Status and Status reason are both optionsets.  Option set have an int value and a text value.  The text value is meta data and the int value is held in the database on the database field.

Default entities have two status values


  • Active = 0
  • Inactive = 1

Status reason have different default values

Status Reason

  • Active = 1
  • Inactive = 2

Out of the box entities State and Status Reason

Out of the box entities can (and often do) have more than two Status Reasons where as custom entities can only have two States.  Microsoft often bend the rules for the default entities because they have created functionality which needs the default entities to behave in a certain way.
It’s useful to know how custom entities work so you can then appreciate how the default entities work and have been changed.  This knowledge will help you work on the default entities because you can take advantage of the added functionality and extra status values.
Below are two examples of the extra status’s for default entities
E.g. Case/Incident
  • Active
  • Cancelled
  • Closed


  • 0 : Open
  • 1 : Qualified
  • 2 : Disqualified
You can see the full list of default entities and their Status and status reasons
Looking at the list gives you an insight to the number of default entities which make up the out of the box CRM functionality.  It will give you an idea of how each entity works and the flow of it.

State and Status reason have different default values

The key piece of information is State and Status Reason have different values and this can be confusing, usually it goes down the lines of

I know State or Status Reason Active = 0 but which one is it.

A quick way to confirm what the Status or Status reason is, is to do an advanced find and use Status or Status Reason in a conditional.  If you then click the download Fetch XML button you can see the values being used

Status active 1
Status active 2
So you know Active Status (statecode) have the value of 0

No Magic Numbers

Magic numbers in development is when developers use number values for status or any option sets but give no indication what the values mean.  This makes reading/understanding the code difficult and extremely frustrating because you often have to go and look up the values.

Wiki gives a good description of Magic numbers in code

here is a good explanation on stackoverflow – What is a magic number, and why is it bad?

Below you can see an example of magic number being used in code, what status is number 6!  If you are lucky the developer will add a comment

if (incident.StatusCode.Equals(6))
//do something incident cancelled
The use of Option set enums makes this much easier to understand.  I believe code should be self documenting through the use of well named variables, methods and classes.
if (incident.StatusCode.Equals(incident_statuscode.Canceled))

//do something incident cancelled


Don’t be lazy, create the Option Set enums and make your CRM code more readable.  I have written a blog on why you should create Enumerations for optionsets.

CRM 2013 – Create Enumerations for option sets

There is a great tool to help you called

CRM Early Bound Generator

I reviewed the tool in the link below

CRM 2013 Tool – CRM Early Bound Generator

Hosk’s Top CRM Articles of the week – 19th June

Article of the Week

Introduction to TypeScript for (Xrm) Developers

A great introduction to typescript from Dave Berry.  He has been slaving night and day for weeks over this, so you owe it him to read it.

Best of the Rest

Resolving Microsoft Dynamics CRM Asynchronous Deadlocks

Excellent article on Async deadlocks.  I have experienced an async problem and it’s a nightmare.  Good article to understand how things work

Don’t let bugs get into production environments

Hosk lecture on not letting bugs out of your Dev environment

A Gotcha with Default Entitlement Assignment on CRM Online 2015 Update 1

It’s always good to know the CRM gotcha’s


A great collection of CRM Bookmarklets to power up your user

Brilliant list of Javascript bookmarklets, the bookmarklet to make all fields editable is awesome!  Implement these and it will save you a bunch of time

CRM Developer Centre gets updated and it looks good

The CRM developer centre is updated, making it easier to use the CRM SDK documentation.

Step by Step – Configure CRM Plugin and Azure Service Bus in CRM 2015.

A concise walkthrough

A gentle introduction to CRM portal development

good explanation of CRM portal dev

nice piece of javascript – Hide fields dynamically based on Field Level Security privileges


Useful piece of Javascript to read field level security privileges on a field

Inconsistent behaviour of DateTime values in plugins

interesting and odd behaviour


The 11 deadly sins of product development

Screaming Architecture

Uncle Bob article

Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile Time Polymorphism)

Behind The App: The Story Of Notepad++

Notepad++ is awesome

Benefits of Code Reviews


The extraction mindset

An article from Seth Godin to make you think

A guide to better decisions

Great article on making decisions

A Guide to Meditation

experts always recommend these books

brilliant concise article on Stress Management 

brilliant post from the ideas of AntiFragile – Learning to Love Volatility 

I must get round to reading AntiFragile

Previous top picks

Hosk’s Top CRM Articles of the week – 12th June

Useful Hosk Links

Hosk list Of CRM 2013 Tools

A list and review of CRM 2013 tools, this will probably work in CRM 2015 as well

Hosk’s CRM Developer Articles

A collection of my favourite CRM Developer articles I have written

MB2-703 – CRM 2013 Customization and Configuration Certification Information

All the CRM 2013 content to help you pass the exam

HoskWisdom – Hosk Developer Quotes

 Words of Wisdom from the Hosk.  I have written over 900 articles, surely I should have said a few memorable things

Don’t let bugs get into production environments

“ If debugging is the process of removing software bugs, then programminUnit Testing and Code Review are such activities must be the process of putting them in. ” – Edsger Dijkstra

Bugs are lazy, good for nothing trouble makers.  They are too lazy to walk to production environments so they wait for you to change some code and jump on board and let you take them all the way to production before they pop out and blow a raspberry at your customers. – Hosk

I have written a number of blog posts on the quality of CRM projects/customizations/code.

During the process of writing these articles (and others) I have become convinced of the importance of keeping the quality of the CRM code high.  The quality of the CRM code is the foundations which the CRM project is built on.  If the quality of those foundations started to weaken the CRM project becomes harder to use, support, extend, debug.

CRM developers needed to keep standards high, quality of code high and stop as many bugs as possible from getting out of the Developer environment and into production.  This can be done by catching as many bugs in your Developer environments before they can escape to production.

Why is it so important?

There are a number of reasons why finding bugs in your development environment is better but main reason is time.  It takes longer to find and fix production bugs than development bugs as shown by this familiar graph

The picture comes this interesting blog post – Quality assurance in software development: When should you start the testing process?

The blog post highlights the cost of funding bugs in production

For instance, a bug identified during conception costs something around zero, but when this same bug is found only after implementation or test, the average cost of repair can get to something between 10 and 1000 times more than in the previous step. When customers find this bug in production environment, the cost of the problem considers all side effects related to it and. That is where things can get serious.

Below are my reasons to not lets bugs out of your development environment

Customers lose confidence when they find bugs

When customers find bugs, it makes them question the quality of the customizations being created and the testing process which has missed the bug.

Bugs frustrate the customer and the developer for different reasons but bugs can delay the testing/using of certain functionality, slowing the momentum of the project/set of changes.

Understanding of business logic fades but the code remains

When you are working on a piece of functionality you are in the flow, you understand the business logic, you understand the code, you are a developing machine.

In a few months time  your knowledge of the business logic will have faded, as will some of the knowledge of the code.  In many ways understanding how the code works is easier because you can follow the code but you might not remember what the code is trying to do or why (business logic)

  • If you have to make a change to this code having unit tests will make it easier to test
  • You can change the code and rerun the tests to make sure it’s still working.
  • You can use the unit test to easily debug the code
  • Tests show the developer what the code should do


When a developer finds a bug whilst writing and testing the code, the developer can fix it quickly whilst they understand the business logic and code.  If the bug is found later the developer will need to reread the specs, ask business analyst and relearn the rest of the code so they can implement a fix.

If the bug makes it to production, the process takes a lot longer to fix

  • A customer finds the bugs and raises
  • The bug is logged by someone
  • The developer will try and recreate the bug.  This could lead to more exchanges asking for more information about recreating the bug.
  • The bug recreated and fixed (once the developer understands the code again)
  • DEV testing
  • Build and deploy in other environments and testing

Imagine how much longer a bug takes to be fixed when it is found in production compared to finding the bug in the Dev environment.  In the example above I have assumed the same developer is fixing the bug but often the bug will be fixed by a new developer which means the understanding of the code, fixing and testing all take considerably longer.

How do we stop bugs escaping to Production

In my experience activities like unit testing, integration testing and code reviews will help find bugs.  In my opinion the most effective way to stop bugs escaping to production is to improve the quality of your code.

Unit testing, Integration testing and code reviews will help find bugs but well designed code will reduce the number of bugs created.

Writing simple well designed code

The main method to stopping bugs is to make the code more simple.  Reducing complexity and designing your code to adhere to the S.O.L.I.D objection orientated design principles will create simple code.

Uncle’s Bob’s articles on SOLID

Here are two more good summaries

Why is writing high quality code which adhere to OO design principles important?  Consider the core hiding place for bugs is within complex code and complex code exists where poor or no design of code exists.

I have written before about why code should be simple and the problems with complex code but I will recap.

Poorly designed code comes under many names, here are a few popular titles

Poorly designed code hard to understand and is usually tightly coupled which leads to code changes affecting large parts of the code.  A change to one class/method can ripple through a large part of the system.

More dependences = more code which might not work after changing

Making changes to poor quality code is difficult, the initial difficulty is understanding the code.  Poorly designed code often has many dependences which increases the difficulty and risk of changing the code due to the increased risk of breaking other parts of the system.  Low quality code doesn’t manage the effects of change well

Badly designed code has no code reuse, the developers have to write new code or copy and paste some code (duplication, very bad).  Creating more code will take longer which is bad but the increase in code will increase the complexity, increase the lines of code to manage, increase the change of more bugs.

When working with legacy code (which is poorly designed code people have given up refactoring)

If the code is working leave it alone

Otherwise make as few changes as possible because it might stop working

There is a risk of unintentional bugs when changing legacy/badly designed code due to the code being complex and difficult to understand.  The cause of unintentional bugs is often responsibilities/dependencies which can link code/classes together.

If you have to work with legacy code or poorly designed code, these two books will help

Unit Testing

The main benefits of unit testing code is not finding bugs.  Unit testing will find some bugs but the real benefits come in improved design of code which is needed to make your code testable.  The biggest benefit I have having unit tests for my code is I can refactor the code with confidence because I can change the code and test it still works.  It’s easier to refactor and redesign the code to improve the design of the code.

Code is never finished, it’s never perfect, it’s exists in it’s current state,  ready to be improved.  I have written before Unit tests are a vital part of emerging code design.  Developers should be constantly trying to improve the quality of their code, simplifying, making the code easier to understand, reducing complexity, separation concerns, increasing cohesiveness of the code.

Developers with unit tests for their code see ways their code can be improved and refactor

Developers without unit tests think, if it ain’t broke, don’t fix it

Code Reviews

I think code reviews are a great net to catch bugs.  In the same way a writer finds it difficult to edit his own writing, developers find logic bugs in their own code.

Developers get so close to their code, it’s difficult to step back and impartially inspect the code, this is where a code review gets someone to not only evaluate the logic of the code.  Code reviews can ensure the quality and design of the code is high and can be an invaluable tool to learn and improve your coding.

Here some benefits of Code review

  • Training/mentor
  • finding logical bugs (many eyes)
  • Increased code reuse
  • Better use of core dll’s
  • A second opinion

Here is a good post on Benefits of code reviews

Integration Testing

Developers don’t like testing their code, they prefer to spend their time creating code (and bugs).  Integration testing is a vital part of software development, to ensure the product is testing from an end users perspective.

CRM Software is complex and it’s difficult for one developer to understand and predict the various combinations.  Developers won’t use the software in the same way as the end user, integration testing will test the software the way a user will use it.


Productions bugs in my personal experience are a painful experience, usually involve plenty of time to understand and recreate the bug in your development environment.    The cost of fixing and moving the fix through the various environments is a cost in time, not to mention its boring.

The emphasis should be on quality and keeping the quality of the code base high by refactoring and improving the design of the code.  Most of a developer/programmers lift is spent inspecting and understanding code, which highlights the importance of keeping it simple and easy to understand.

CRM Developer Centre gets updated and it looks good

CRM developer centre I noticed the CRM Developer website has been spruced up I thought I would write a quick blog about this because I think new CRM developers should definitely head towards the new site.  The change isn’t huge it is a good move for CRM Developers who are just starting out in CRM development.

What is the CRM SDK?

There is the actual CRM SDK, which you download Microsoft Dynamics CRM Software Development Kit (SDK) for CRM Online and on-premises CRM 2015 This gives you a bunch folders and files with sample code and the all important CRM dll’s and maybe a link to the CRM developer toolkit as long as you haven’t downloaded CRM 2015 (Where is the CRM Developer toolkit for CRM 2015?) CRM SDK download When I talk about the CRM SDK, I am talking about the documentation.  In the download it’s the CrmSdk2015.chm but I use the online documentation because it’s easier to search. Software Development Kit for Microsoft Dynamics CRM The CRM SDK documentation is awesome but I distinctly remember finding it difficult to use when I was learning CRM development.

Why is the CRM SDK hard to start developing with?

The CRM SDK is a huge and when a CRM developer first starts looking at it can be overwhelmed by the amount of information. When a CRM developer first opens the CRM SDK documentation it’s like walking into the British Library (largest library in the world) looking for a book to get started with programming.

The CRM SDK is a fantastic document and the content is some of the best documentation I have read for product/toolkit but in this strength lies it’s weakness.  The amount of documentation makes it very difficult to order and organise so CRM Developers can find the information they are looking for. Many times I have found useful information

  • tucked away in a section I didn’t know existed
  • A section I  have never read before
  • Wasn’t an obvious place to look.

CRM SDK documentation = CRM Developers bible

I view the CRM SDK documentation as the core documentation for CRM developers, it’s vital CRM developers know how awesome it is, how to use it effectively to clarify how CRM works when they are not sure.

Always start with the CRM SDK

The CRM SDK works brilliantly if you are searching for specific parts of the CRM SDK like OrganizationService, plugin variables. The CRM SDK documentation works well for new releases CRM 2015 SDK – Why you should read the What’s new for developers What’s new in CRM 2015 SP1 for developers, customizers and admins The CRM SDK has lots of example code and offers a good way to learn different CRM customizations.

The biggest benefit of the CRM SDK documentation is it’s written by the creators of the CRM SDK and accurately details how the code works instead of how a CRM developer believes the code works. Most times I read the CRM SDK I learn something new.

The downsides of the CRM SDK documentation is it can read like a manual/reference book, this style is excellent for CRM developers who have some experience but can be confusing for new CRM Developers.  There is a lack of screenshots which can be a barrier to understanding new concepts and examples.

Why the CRM DEVELOPER Centre update is good

Once again the Hosk has gone widely off track, the CRM developer centre has been updated and I think it’s a good thing because

  • It’s a front end to the CRM SDK
  • It’s modern and sexy looking
  • It’s built so it can be consumed on mobile devices
  • The search brings back CRM content not all MSDN

The headings give a quick path to relevant sections of the CRM SDK.  It would be great if Microsoft could invest more time trying to visualise the CRM SDK which would encourage more developers to dip in the CRM SDK. The CRM SDK documentation is massive so it’s difficult to dice, slice and display the information in ways to make it easier to find the information you want but Microsoft have already created the information and the challenge is ease accessibility of it.

Hosk’s Top CRM Articles of the week – 12th June

Article of the Week

The article of the week is my article is the excellent and I want as many people as possible to go and have a look at his first steps in towards creating a developer toolkit replacement.

Possible developer toolkit replacement

I will add my blogs on the subject below

Where is the CRM Developer toolkit for CRM 2015?

CRM Developer Toolkit Alternatives

I will add the Connect suggestion here has 66 votes which is great because a week ago it had 9.

Best of the Rest

XRM code snippets

Some useful Javascript code snippets

CRM 2013 – Disabling a subgrid

Hosk article on how to disable a subgrid without actually disabling it.

Web API preview documentation released

The new Web API stuff, in an odd trial but unsupported offering!!!?!?

New XrmToolBox Plugin: Export to Excel

Don’t be limited by excel when exporting records with the

Getting the CRM Developer toolkit working with Visual Studio 2013

Steps on how to get the current CRM developer toolkit working with visual studio 2013

Upgrade vs Rebuild, Interest vs Responsibility

Good article from CRM MVP Leon Tribe on considering what to do with your customizations when upgrading

Turbo Forms: Get your JavaScript ready for CRM2015 Update 1

Scott Durow gives the lowdown on getting your scripts into shape to be able to use them with the new CRM 2015 SP1 turbo forms.

Create Button in CRM 2013/2015 Form without a Field using Javascript

A button without a field, what is this magic

Dynamics CRM – Security Role Automatically Assigned to imported Teams

Cheeky salesperson role automatically assigned on importing teams.  Probably some kind of reason for this but very annoying if you are not aware of this behaviour

Improve CRM query performance using compatibility version 120 with SQL 2014

Dramatic performance improvement when switching to SQL 2014

Scalability considerations for CRM / SharePoint integration

good article and worth a read

C# Development Tips for Microsoft Dynamics CRM

Great article on implementing C# dev to CRM

Kinect and CRM!!

It’s madness I tell you but it looks cool


“How is Software Like a Skyscraper?”

Martin Fowler – Is Design Dead

great article on YAGNI by Martin Fowler

very interesting article on the history of lean development, I don’t know much about lean development but it sounds like agile without the rubbish bits

Empires fall: Decentralize your code to avoid total collapse

The 8 Best Programming Books to Read Right Now if You Want to Distinguish Yourself

Software engineers are lazy bastards

31 Of The Best Kept Secrets Of Great Programmers

Microsoft: People Have Smaller Attention Span Than A Goldfish

Improving Your Craft with Static Analysis

What’s Fixie and Why Should C# Programmers Care?

TypeScript Futures

OO principles from Head First Design Pattern

The dangers of spaghetti code



Do something syndrome

The Disease of Being Busy

Neil Gaimen and Kazuo Ishiguro

Deep Habits: Spend Six Months to Master Skills

Strategy More: Inc. Success Bill Gates Warren Buffett
How Bill Gates, Warren Buffett, and 8 other successful people spent their summer vacations when they were younger

Previous top picks

Useful Hosk Links

Hosk list Of CRM 2013 Tools

A list and review of CRM 2013 tools, this will probably work in CRM 2015 as well

Hosk’s CRM Developer Articles

A collection of my favourite CRM Developer articles I have written

MB2-703 – CRM 2013 Customization and Configuration Certification Information

All the CRM 2013 content to help you pass the exam

HoskWisdom – Hosk Developer Quotes

 Words of Wisdom from the Hosk.  I have written over 900 articles, surely I should have said a few memorable things

CRM 2013 – Disabling a subgrid

This blog post will look at possible ways to disable subgrids in CRM 2013.  I had a requirement if a user made a case restricted then the case couldn’t be linked to any other cases.


  • On the case form we had functionality to select a parent case and a subgrid to add child cases.
  • Case had a restricted bool field
  • Restricted cases could not link to any other cases

If the user set restricted to Yes I had to disable the subgrid and the case lookup, e.g. stop the restricted case from being linked

Disabling the case lookup field was was straightforward


Frustratingly for me subgrid control does not have a setDisabled method, this means disabling the subgrid would not be as straightforward.

Disabling a sub grid

This is a different story, a story with twists, frustration

An unsupported way

// Disable a subgrid on a form
function disableSubgrid(subgridName) {
document.getElementById(subgridName + "_span").disabled = "true";

I’m not going to consider putting in unsupported changes because if you do then Microsoft will unsupport your customizations.  This probably doesn’t sound like much of a threat but if you find a bug with out of the box functionality Microsoft won’t even look at your customizations due to the unsupported code.  When the customer then finds out they have no Microsoft support because of your code.

Why you shouldn’t put unsupported customizations in Microsoft Dynamics CRM

From the Hosk Wisdom page 🙂

Don’t even think about making unsupported changes in CRM because Microsoft will un-support your CRM if they find out – Hosk

Don’t do unsupported CRM customizations, 99.9 percent of the time there is another way.  For the 0.1, tell the customer its unsupported – Hosk

Other Options

If I can’t disable the subgrid (in a supported way), what other options do I have?

Disable buttons on subgrid

Scott Durow the Ribbon Workbench creator has an excellent article on disabling the add new button.  This hiding rule could be set on all the add buttons on the subgrid.

Show or hide the ‘Add New’ button on form sub-grid based on the value on the form

It’s worth reading this article just to look at the image which explains what buttons on the sugrid link to what buttons on the command bar inside the Ribbon Workbench.

In theory this option should work but it would involve setting up enable rules for all the buttons on the subgrid.

Hiding and Showing

Hiding and showing sounds like a kids TV show, actually I’m thinking of Show me Show Me

My initial thought was to disable the grid but in CRM 2013 sub grid doesn’t have a setDisable, which stopped my plan but looking at the CRM SDK I can see subgrids control does have a setVisible.

This line of supported code will hide the subgrid 


This shows it again


The code above worked and it did hide the subgrid, the problem I had was it looked odd because it left a big blank white space where the sub grid was hiding (not very well).

The other problem is sub grids load asynchronously.  I needed my code to work on the form OnLoad event but when it came to hiding the the subgrid it was loaded yet and would throw an error.

To get round this error, I would need to wait until the subgrid had been loaded, so I could subsequently hide it (which doesn’t seem right when I say that out loud)

I created this code to wait until the subgrid is loaded.

  function ShowSubgrid(show) {
        var Subgrid = Xrm.Page.ui.controls.get("ChildCasesGrid");

        if (Subgrid == null) {
            setTimeout(function () { ShowSubgrid(show); }, 2000);
            //if the grid hasn’t loaded run this again when it has

        } else {
            if (show) {
            } else {

This works but I don’t like having wait’s in code, particularly in a form load where you don’t want to add an extra lines running on a form load which usually takes a while and the form load performance is extremely visible to a user.

I am of the opinion to avoid waits in the code at all costs, if you have a wait in the code you have a bug/problem waiting to happen.  Most of the time its worth the effort to find an alternative solution and reduce the complexity of your code.

A wait in code is similar to seeing +1 in some code.  The code is working round a problem rather than resolving the cause.

When considering form loads in CRM, it’s probably comparable to the frustrating time it takes for a computer to boot up in the morning.  The time may only be a short amount of time but it feels about four times as long in real time.

Whilst a form is loading the user has nothing to keep them occupied so the time feels longer, try to keep forms loads as quick as possible.  Here is a blog post I wrote on performance issues

CRM 2011/2013 Investigating CRM Form Performance issues

QUICK BREAK TO LOOK AT CRM 2015 SP1 new GridControl stuff

Looking at the CRM SDK form events page, initially it loads the latest page for CRM 2015 and I noticed CRM 2015 SP1 has a new special Subgrid OnLoad event.

There is a new page Write scripts for subgrids, there is now a new GridControl and you can look Grid objects and methods to see the new cool things you can do

The Grid Onload method is cool but there are some other interesting methods I noticed

The grid has

  • getRows
  • getSelectedRows
  • getTotalRecordCount

From the Grid you can get do a getRows and from here there are some great helper methods in the GridEntity

  • getEntityName
  • getEntityReference
  • getId
  • getPrimaryAttributeValue

and other stuff which you should go and check out yourself

Back to CRM 2013 subgrids

After some developer brainstorming I decided to try putting the subgrid into a section.  The advantages of this is you can hide/show a section without having to wait for the form to load.

Another advantage is when you disable a section it hides itself much better, the form acts as if it wasn’t there at all, unlike hiding the subgrid which leaves a white space the same size as the subgrid.

To hide or show a subgrid you have to toggle the visible flag using the setVisible method





Plugin Option

Maybe the most straight forward to resolve this issue is to have a plugin which is triggered on change of parentCase field.  When setting this you could check to see if the child or parent case is a restricted case and throw a pluginException


The blog’s title is about disabling a subgrid but the goal was to stop restricted cases from being linked.

The benefit of Javascript customizations is they are instant because the code works on the client side.  Plugins are server side, so their is a delay in capturing and responding to the changes.

Javascript can often offer a better user experience because CRM developers can react instantly to changes in values and hide/disable fields.

Server side changes are less responsive and cannot guide the user in the same way Javascript validation code can but has to catch the values and decide whether to roll them back.  Server side validation can be more frustrating to CRM users because they have made the changes, only to find them being rejected.

In this scenario the plugin/server changes are in one place, where there are lots of Javascript code changes to do the same thing.

A key skill of a CRM developer is selecting the right customization for the right job