Converting to CRM 2011 JavaScript: Form Elements

One of the most fascinating things I found during the creation of the CRM Migration Assistant is the different methods developers use to access CRM form fields, and other form elements.

Normally, people access a form field using the following style of JavaScript:

crmForm.all.name

This is the normal and perfectly acceptable (and supported) method for referencing CRM form fields.

But, for various reasons, I’ve also seen fields reference using these crmForm methods:

crmForm.name
crmForm.elements["name"]
crmForm.all["name"]
crmForm["name"]

This is perfectly acceptable JavaScript and the CRM 4.0 object model had no objection to this practice, so all of these methods seemed to work.

In fact, accessing CRM form fields using the JavaScript document object using these methods worked as well:

document.all("name_c")
document.all["name"]
document.getElementById("name_c")

The real question is: Will these methods continue to work when the organization is upgraded to CRM 2011?

The answer is: If you have used standard and supported methods within your JavaScript, then yes, the code will be supported.

This means referencing all of your form fields using the standard access model:

crmForm.all.name

Other options may or may not work correctly. Your experience my vary depending on which of the above methods were used.

Fortunately, the CRM Migration Assistant converts all of these "unsupported" form field access types into fully-supported CRM 2011 code using Xrm.Page.getAttribute and Xrm.Page.getControl, depending on how the field was being used.

If you haven’t already, download the trial version of the CRM Migration Assistant and convert some of your questionable JavaScript through the conversion process.

If you run into any conversion issues, send me a code sample so that I can update the conversion process.

Leave a Reply 0 comments