Using the CRM metadata to generate Visio entity diagram

 

September 01, 2010

The CRM 4.0 SDK includes a cool little project called “metadatadiagramconsole” that allows you to analyze CRM metadata programmatically to generate a Visio diagram depicting relationships of some or all of the entities into CRM deployment.

As I have been working my way through the SDK, I spent a little time in this recently.

It’s a great little project to keep me moving forward with C#, but it tends to generate diagrams that contain way too much detail if all you’re trying to do is to show entity architecture of the custom solution.

I’ve learned couple of tricks and made a couple of modifications to simplify the output and thought I might share them with you.

After making the modifications suggested in the readme document to connect it to a CRM deployment, I found a couple problems related to using the project type only analyze certain entities. First of all, you need to change the file name in the project when you’re not using the all entities option. The current method of naming, can cause an error if you select too many entities.

    builder.BuildDiagram((string[])entities.ToArray(typeof(string)), "All Entities"); 
    filename = "AllEntities.vsd";   
}   
else  
{
    builder.BuildDiagram(args, String.Join(", ", args));
    filename = "BITPEntities.vsd";
}

Another issue that you run into, is that the tool maps a large number of relationships that you may not want to include. I address this by adding all the entities that I want excluded from my diagram to the _excludedEntities array which is defined at the beginning of the DiagramBuilder class. In this case, I was trying to get a very specific diagram that would be easier to maintain and excluded most of the system entities:

        // These entities exist in the metadata but are not to be drawn in the diagram. 
        static Hashtable _excludedEntityTable = new Hashtable();   
        static string[] _excludedEntities = new string[] {"list", "annotation", "account", "activitypointer", "attributemap", "asyncoperation", "bulkimport", "businessunitmap","cc_securitybehavior", "cc_securitybehaviorrole", “commitment",  "crmi_tooltip", "custom_audit", "custom_audit_detail", "customeraddress", "displaystringmap", "documentindex", "email", "entitymap", "fax", "gi_fieldlevelsecurity", "importconfig", "integrationstatus", "invoice", "invoicedetail",
"internaladdress", "letter", "opportunity", "opportunityproduct",
"phonecall", "privilegeobjecttypecodes", "product", "quote", "quotedetail",
"roletemplate", "roletemplateprivileges", "salesorder", "salesorderdetail",
"serviceappointment", "statusmap", "stringmap", "stringmapbit",
"sw_license", "sw_licensemanager", "sw_localizedstring", "sw_lookupcolumn", "sw_lookupdefinition", "sw_lookuplabels", "sw_lookuptemplate", "sw_lookupviewtranslation", "sw_pickist", "sw_retrievemultiplequery", "sw_retrievequery", "sw_tracelog", "task", "lead", "contract", "contractdetail", "service", "bulkoperationlog", "appointment", "equipment", "activityparty", "customerrelationship", "customeropportunityrole", "incident", "pricelevel", "duplicaterecord", "bulkdeletefailure", "transactioncurrency"};

Unfortunately, this did not keep the code from drawing all these entities. Further analysis showed that I needed to add one more line of code in the DrawRelationships method. I added the red code below to the existing code to ignore any relationships with excluded entities:

// Do not draw relationships involving the entity itself, SystemUser, BusinessUnit, 
// or those that are intentionally excluded.   
if (String.Compare(entity2.LogicalName, EntityName.systemuser.ToString(), true) != 0 &&   
    String.Compare(entity2.LogicalName, EntityName.businessunit.ToString(), true) != 0 &&   
    String.Compare(entity2.LogicalName, rect.Name, true) != 0 &&   
    String.Compare(entity.LogicalName, EntityName.systemuser.ToString(), true) != 0 &&   
    String.Compare(entity.LogicalName, EntityName.businessunit.ToString(), true) != 0 &&   
!_excludedEntityTable.ContainsKey(entity2.LogicalName.GetHashCode()) &&
!_excludedRelationsTable.ContainsKey(attribute.LogicalName.GetHashCode()))

Ultimately, I ended up with a much simpler chart. I hope this idea works for you.

Stephen Noe, MCITP-CRM

Advertisements

About stephenvnoe

CRM & XRM solution architect and project lead. I provide CRM design, services, mentoring & support to all manner of front office solutions and CRM projects.
This entry was posted in CRM, CRM 4.0, Extending and tagged . Bookmark the permalink.

4 Responses to Using the CRM metadata to generate Visio entity diagram

  1. Wendell says:

    Any idea if the CRM 2011 SDK has a metadatadiagramconsole. I would like to work with the entities in Visio.

    Like

  2. CRM 2011 SDK has Meta Diagram Generator source code. #sdk\samplecode\cs\metada\diagram

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s