Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

|

Resolving JavaScript Dependency Issues in CRM 2011 UR 12 and UR 13

Post Author: Joe D365 |

It's not uncommon when working with large amounts of JavaScript files, whether you've created them or are using third party libraries, to run into a dependency issue. It's a significant enough problem that libraries like RequireJS exist to address it. However, when developing for CRM, coders lose some of the control over the application pipeline that they may typically have when creating custom web applications.

In an effort to improve performance and shave some valuable time off loading of forms, Microsoft modified the loading behavior of JavaScript files in Update Rollup 12 and higher, and in doing so, have created an issue with dependencies between those files. The solutions most likely to be affected by this change are ones that have a lot of interdependencies between libraries and are of a significant size or rely on outbound connections like fetches.

To resolve this, you can write a simple function to determine the availability of your given resources. This is similar to the methods used when working with jQuery in native web applications that utilize the browsers existing methods for checking loaded status. The method is as follows:

function onScriptReady(name, callback) {

var interval = 10;

window.setTimeout(function () {

if (window[name]) {

callback(window[name]);

} else {

window.setTimeout(arguments.callee, interval);

}

}, interval);

}

To use, simply find a method that has a dependency, and wrap that function in the onScriptReady function. For instance, given the following script that relies on a global variable:

var aValue = GlobalVariable.prototypedMethod(input);

You could wrap the function like this:

onScriptReady("GlobalVariable", function(t){

var aValue = GlobalVariable.prototypedMethod(input);

});

You can make the function more complex if you like, to handle things like multiple dependencies or check to ensure if a script is being used on a UR 12 or 13 solution or not, but this simple implementation should be good enough for resolving most JavaScript dependency issues in CRM 2011 for UR 12 and beyond.

If this was helpful, you might also want to refer to some of our other blogs on using JavaScript in Dynamics CRM.

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

One comment on “Resolving JavaScript Dependency Issues in CRM 2011 UR 12 and UR 13”

  1. This was addressed in Update Rollup 15. Loading web resource script files now load in the order in which the listed in the form properties.

PowerObjects Recommends