Dynamics CRM JavaScript loading has changed drastically through the years — maybe some day, it will actually make sense, but I digress. Currently in D365 9.x you’re able to specify the Dependent JavaScripts in the interface, and it’s supposed to asynchronously load it. Sometimes, this works great. For some reason, on some forms, and some seemingly random times, it will just not load the dependent script and you’ll get an error. I’ve not been able to replicate why it happens, but I have had to make a really dumb workaround for the time being, and I figure I’d share it — even though it’s a bad idea and would be unnecessary if Dynamics CRM weren’t a dumpster fire.

If you want to load another JavaScript using the built-in D365 jQuery, you can follow this pattern in your onLoad script on the Form Script. You can replace the “formscriptslib.js” with whichever script you’re trying to load. The “magic” is in the eval command which runs the script after $.getScript/$.ajax starts it. Otherwise it doesn’t appear to be executing at all.

function onLoad() {
var runOnLoad = function() {
console.log("put your onLoad scripts in here");
var loadOnLoad = function() {
if (typeof util === "undefined") {
console.log("Form Scripts FAILED to load. Loading manually.");
} else {
console.log("Form Scripts Loaded Correctly. Continuing to run OnLoad");
if (typeof util === "undefined") {
console.log("if it's still not loaded, run this script again");
setTimeout(loadOnLoad, 1000);

function loadScripts(fOnLoad) {
if (typeof window.$ === 'undefined' || typeof window.$.when === 'undefined') {
window.$ = parent.$;
cache: true
window.parent.$.loadScript = function(url, callback) {
url: url,
dataType: 'script',
success: callback,
async: false //load synchronously
var urlOfScript = function(jsFile) {
var scriptElements = document.getElementsByTagName('script');
var i, element, myfile;
for (i = 0; element = scriptElements[i]; i++) {
myfile = element.src;
if (myfile.indexOf(jsFile) >= 0) {
var myurl = myfile.substring(0, myfile.indexOf(jsFile));
return myurl;
var directoryOfScript = function(jsFile) {
var fullUrl = urlOfScript(jsFile);
var returned = fullUrl.substring(fullUrl.indexOf('.com') + 4, fullUrl.indexOf('Form')); //set the "Form" value to whichever location you're putting scripts for Forms
return returned;
var formDirm = directoryOfScript('Ticket.js');

$.getScript(formDirm + "/formscriptslib.js"),
$.Deferred(function(deferred) {
).done(function() {
if (typeof util === "undefined") {
if (fOnLoad) fOnLoad();
console.log("place your code here, the scripts are all loaded");