Creating Your Own Business Unit

Business Units are one of those dicey concepts in Dynamics where if done right – they make sense and are of big value to your implementation.

But when done wrong, they can be a black hole that makes your life very hard to recover from.

When discussing with clients why they need a business unit there are a few things I generally look for;

  • Do you have groups within your organization that need to keep their data separate from one another?  The best example being a parent company with subsidiaries which need to use the same system but cannot see each other’s data (because they are partners).
  • Are you trying to do implement security with a Business Unit (i.e., what people can and cannot do?).  If so, you should look at security roles.

Generally, when implementing Business Units, I encourage customers not to go too many levels deep in their first implementation.

On a recent project, I had to some solution deployment code and wanted to figure out how to create a Business Unit from the SDK.  The key to the creation of any business unit is the hierarchy so the first thing you need to do is get the reference to the parent business unit id where you want your business unit to reside in.

Once you have done that, it’s as easy as creating the business unit code, assigning the new EntityReference and creating the object.

QueryExpression query = new QueryExpression("businessunit")
ColumnSet = new ColumnSet(true)

EntityCollection businessunits = cn.CrmService.RetrieveMultiple(query);
if (businessunits.Entities.Count == 1)
Entity busunit = new Entity("businessunit");
busunit["name"] = "Test Greg Unit";
busunit["parentbusinessunitid"] = new EntityReference("businessunit", new Guid(businessunits[0].Attributes["businessunitid"].ToString()));


Now obviously not the cleanest code but it does show you how easy it is to create a business unit.  If I was going to be more elegant about this code, I would be evaluating the parent unit on some additional criteria in my code and not simply be taking the first one that comes down.

Interestingly enough, when you run this code a second time, the primary business unit (the parent) now comes down with 9 attributes, whereas the one that I created has 17, so that could be an interesting keying off point as well.

More to dig into.

Post A Reply

%d bloggers like this: