Microsoft Dynamics CRM Online 2015 Update 1 (Spring 2015)

Microsoft Dynamics CRM Online 2015 Update 1 (Spring 2015) - ReferenceError: $ is not defined error

We upgraded to Dynamics 2015 Update 1 last week. On coming in on Monday morning and trying to work in Dynamics, the first thing I noticed was the speed of the form loading - much improved! Thank you Microsoft for (finally!) paying attention to this - Dynamics was a pain to work in before this speed increase.

However, the second thing I noticed was that we were getting errors from our custom scripts that use jQuery - the error being "ReferenceError: $ is not defined error" - $ being changed with 'jQuery' when that reference was being used.

I could see (through the FireFox network inspector) that jQuery was being loaded on the page, and it was available in the console, so the fact that our scripts couldn't access it was somewhat confusing.

A quick support case was opened with Microsoft, who later called up for the usual screen sharing support session. The support operator (Gitanjali) tried a few things with me, to no avail. Eventually she switched the system back to "Legacy form rendering" (Settings > Administration > System Settings > "Use legacy form rendering" = Yes) which cured the problem - surprise surprise since we had had no problems before the upgrade!

Gitanjali suggested that this was the temporary workaround necessary, and that Microsoft were aware of various issues with the new form rendering, including this one, and that it would be fixed in a future patch.

While accepting this line from Gitanjali as the official Microsoft position, I wasn't ready yet to give up on the new speedy forms! So I dived into the code to investigate a little further - and then I noticed that the user-defined JavaScript files are now being loaded into the page via an iframe - meaning that they don't have access to JavaScript variables defined in frames further up the frame stack.

Happily, this meant that I could simply test for the existence of '$' as an object, and if undefined, point it to the variable already defined higher up the frame stack, as follows:

if (typeof($) === 'undefined') {
	$ = parent.$;
	jQuery = parent.jQuery;
}

Hey-ho, problem fixed, and we can continue using the new speedy forms! Happily, all of our jQuery-related code is in a single common functions file which is used to support various entity-specific code, so only a single update to our code base was necessary :)

I hope that this helps somebody else out having the same problem! Or alternatively feel free to get in touch with us if you would like help with your Dynamics installation...

Contact Us or give Us a ring on +44 (0)118 907 6212 and +34 938 021 278

Share this post