JavaScript Upgrade Strategy #2: Upgrade your object model

After you get your development up and running, one of the first things you need to do is to convert your JavaScript code-base from the Dynamics CRM 4.0 object model to the CRM 2011 object model.  Let us review that process:

 

Tools

If you are not in the mood to convert all of your JavaScript by hand, there are some free or commercial conversion tools available:

 

Custom Code Validation Tool

This is a free tool from Microsoft that reviews your existing JavaScript and reports any issues that might prevent the upgrade to Dynamics CRM 2013.  While it does nothing to help you convert your code to the newer object model, it will at least tell you where some of your issues are.

 

JavaScript Converter (free)

This free converter converts a single segment of code at a time using a search and replace operation. A list of conversions may be found here.

 

Transformer! for Dynamics CRM (commercial)

Transformer! for Dynamics CRM is our commercial conversion application. Transformer! converts an entire organization’s JavaScript at one time. It also handles things like converting unsupported coding and conventions into JavaScript that is compatible with Dynamics CRM 2011 and above. I am a bit biased, but I think this is the best bang for your buck when it comes to upgrading your JavaScript.

 

Code Conversion Categories

Quite some time ago I decided to add a feature to Transformer! which would allow me to guestimate the amount of work required to convert any one particular piece of JavaScript.  Here is the table that I created:

 

Simple

This is a very straightforward conversion from one object model to another. For example:

crmForm.all.name.DataValue = “my company”;

to

Xrm.Page.getAttribute(“name”).setValue(“my company”);

 

Difficult/Tedious

The next level up is more manual labor, but it is still possible with a medium amount of effort.

// No requirement
crmForm.all.new_field.req = 0;
crmForm.all.new_field.setAttribute("req", 0);

// Recommended
crmForm.all.new_field.req = 1;
crmForm.all.new_field.setAttribute("req", 1);

// Required
crmForm.all.new_field.req = 2;
crmForm.all.new_field.setAttribute("req", 2);

converts into:

Xrm.Page.getAttribute("new_field").setRequiredLevel("none");
Xrm.Page.getAttribute("new_field").setRequiredLevel("recommended");
Xrm.Page.getAttribute("new_field").setRequiredLevel("required");

 

Hard

An example of the hard category would be SOAP calls.  There is not a really good way to programmatically convert them so you resort to a manual conversion/rewrite process.

 

Impossible

Some things do not convert at all, either because of the technique or technology used, or because they are no longer applicable.

You will find the following examples:

  • Button manipulation code
  • Inline grids

 

What the hell were they thinking?

I have seen code that in all honesty, is scary.  In some cases, very scary.  Sometimes it is because the personally really knew what they were doing, in others it was because the person did not know what they were doing.  Regardless, you sometimes see code that is just better if you threw it away and found a better way around the problem.

Leave a Reply