When two JavaScript files contain two identical function names, e.g. onLoad, and both JavaScript files are used on the same form in Dynamics CRM, then unexpected behaviour may occur. The unexpected behaviour will occur because the incorrect JavaScript function may be called, as shown in the example below.

Conflicting JavaScript function names can occur when two developers create two JavaScript files containing the same name, or when a third party library has a function name that has been used by a developer in a JavaScript file. Conflicting JavaScript function names are also more likely to occur when the function name is generic such as onLoad. To prevent conflicting function names, we are going to use JavaScript name spacing.

The example below shows how unexpected behaviour can occur when multiple JavaScript libraries with conflicting function names are used on the same Dynamics CRM form. For the example, I created a Dynamics CRM 2015 online trial.

Firstly, create two JavaScript files with the code below.


Then, configure the contact form to use both JavaScript files as per the below screen shot.

dynamics crm contact form


When the contact form is loaded, you would expect to see an alert with “Expected Text” as per the Contact.js code. Actually the “Not Expected Text” is displayed when the Contact form is loaded. I suspect this is caused by the order in which CRM Dynamics references the JavaScript files when building the Contact form.

Not Expected Text conflicting JavaScript methods

To fix this, we will introduce name spacing into the JavaScript files. It is out of this blogs scope to explain JavaScript name spacing but there are plenty of online articles explaining it just do a google search. Below are the updated JavaScript files.


Now we can edit the Contact form properties to explicitly call the onLoad function from the Contact.js file by specifying contact.onLoad as the function to invoke as per the image below.

dynamics crm contact onload


When the contact screen is opened we now get the “Expected Text” being displayed.

dynamics crm expected text alert