CRM 2011 ERD Designer

I just released my first CodePlex project, the CRM 2011 ERD Designer!
It can be downloaded from http://crm2011erd.codeplex.com/

The CRM 2011 ERD Designer is a Silverlight 4 application that is packaged as a Managed CRM 2011 Solution. This tool allows you to build ERD (Entity relationship diagrams) that are dynamically updated based on the published CRM entities and Fields; you can create/edit/remove entities and fields from the ERD designer. The tool allows also printing the diagrams.

Image

Note This release is currently in Beta so please provide feedback in the discussion area for any areas of improvement.

The tool has the following Features

o             Add new entity
o             Add new Field
o             Relationship details
o             Save from Entity ribbon
o             Edit Entity
o             Edit Field
o             Edit Relationship
o             Add entity to Diagram
o             Remove entity from Diagram
o             Remove field from Diagram
o             Remove system fields from Diagram
o             Delete Entity
o             Delete Field

Installation

1. Download the CRM 2011 ERD Designer and import it into CRM 2011 On Premise or CRM Online.
2. Refresh the browser.
3. You can then access CRM 2011 ERD Designer within the Settings Area by selecting ERD Diagrams under the Extensions menu option.

Note: As it is a managed solution it can be completely removed from CRM by selecting to delete the solution from the Solutions View in CRM.

To make this project I used the following components

o             Silver Diagram SDK
o             MVVM Light Toolkit
o             CRM Developer Toolkit
o             Silverlight Control Toolkit
o             Menu and Context Menu for Silverlight 4.0
o             MEFedMVVM

So if you download the source code and want to build the solution you will need to

1) Download the Silver Diagram SDK from the SilverDiagram site (just copy the SD.XXXX DLL’s).
2) Download the CRM 2011 SDK from Microsoft site and install the Developer Toolkit that is inside the sdk\tools\developertoolkit folder
3) Download the MVVM Light Toolkit from Codeplex site.
4) Download the Menu and Context Menu for Silverlight 4.0 fromCodePlex site
5) Download MEFedMVVM from CodePlex site

Enjoy It!
Damian Sinay

Using encodeURIComponent when using ODATA queries in JavaScript and Dynamics CRM 2011

This week I ran into an issue that took me a while to figure related to the ODATA queries in Dynamics CRM. This might be a common mistake for other CRM and ODATA REST developers so I wanted to share it here.

Problem description

Here was the most difficult thing; there was not error at all and neither any error message. The JavaScript code that was put on an entity form customization just didn’t work as expected. It was not returning a record that we knew existed in the CRM system. The code looked similar to this

       var serverUrl = Xrm.Page.context.getServerUrl();
       var ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;

       var contactReq = new XMLHttpRequest();
       contactReq.open(“Get”, ODataPath + “/ContactSet?$filter=EMailAddress1 eq ‘” + email + “‘ and StatusCode/Value eq 1”, false);
       contactReq.setRequestHeader(“Accept”, “application/json”);
       contactReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
       contactReq.onreadystatechange = function () {
                  contactEmailReqCallBack(this, changes, a, guid);
       };
       contactReq.send();

 

Basically this code requests a contact by looking at a specific email address that is passed to the parameter email. On my case the code was working for some emails and not for others, I realize the ones that were not working were like firstname+lastname@gmail.com for example. So the URL was formed as follows

http://crm2011/org/XRMServices/2011/OrganizationData.svc/ContactSet?$filter=EMailAddress1 eq ‘firstname+lastname@gmail.com‘ and StatusCode/Value eq 1

it didn’t return any record even though there was a contact in the CRM system with that email address. So, what was the problem here? The problem was the + sign is interpreted as space in the URI as well as other characters might be wrongly interpreted, like for example the / char.

The solution

Use the encodeURIComponent function to encode the email address properly in the URL. Our code changed now looks as follows:

       var serverUrl = Xrm.Page.context.getServerUrl();
       var ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;

       var contactReq = new XMLHttpRequest();
       contactReq.open(“Get”, ODataPath + “/ContactSet?$filter=EMailAddress1 eq ‘” + encodeURIComponent(email) + “‘ and StatusCode/Value eq 1”, false);
       contactReq.setRequestHeader(“Accept”, “application/json”);
       contactReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);   

contactReq.onreadystatechange = function () {
    contactEmailReqCallBack(this, changes, a, guid);
};
contactReq.send();

Conclusion

Never forget to use the encodeURIComponent function when passing parameters on your ODATA queries!

I hope this helps others to ovoid a problem like the one descripted here.

For all who like to work with ODATA services in Dynamics CRM here is a great tool that will help creating the queries. http://crm2011odatatool.codeplex.com/