MAJOR EDIT 1 Below is the description of my original issue but I've discovered that Chrome and Firefox are both loading the libraries correctly. It's IE 9/10 that will not work at all, even upon repeated refreshes. However, once I open the developer console and reload everything works fine.
I've read this post about the issue and followed the outlined steps. The problem is that jQuery is not reliably/consistently loading in IE 9/10, Chrome, or Firefox.
I'm also not able to, with 100% reliability, repeat the issue. However, what usually happens is that after I publish a change in my custom web resource, and reload the form, I will get "jQuery is undefined" in the developer console. Subsequent reloads will not display the error and there doesn't seem to be a difference in behavior if I clear the cache or not before reloading.
Here are some specifics of my implementation:
- I'm using the CrmFetchKit library which depends on jQuery.
- In an attempt to make this work I've combined the two libraries into one web resource. The thought behind this is that the error always comes from CrmFetchKit which says to me that that file has no issue with being properly included.
- My code below.
- My function 'genericFetch()' is set in the onChange event handler for a lookup attribute on my experimental form.
- Everything works as expected (even if the js is super ugly) when jQuery is available.
I'm happy to provide more information and/or screenshots if requested.
// Fetch XML generic fetch format
function genericFetch(entity, targetField, returnFields, searchSource)
{
returnFields = returnFields.split('|');
var searchValue = Xrm.Page.getAttribute(searchSource).getValue();
if(searchValue)
{
searchValue = searchValue[0]['values'][1]['value'];
}
else
{
return false;
}
function onFetchError(xhr, status, errorThrown)
{
var errormsg = $(xhr.responseXML).find('Message').text();
alert('CrmFetchKit-Error occured: ' + errormsg);
}
var fetchXml = ['<fetch version="1.0" output-format="xml-platform" mapping="logical">'];
fetchXml.push('<entity name="' + entity + '">');
var len = returnFields.length;
for(i=0; i<len; i++)
{
fetchXml.push('<attribute name="' + returnFields[i] + '" />');
}
fetchXml.push('<filter type="and">');
fetchXml.push('<condition attribute="' + returnFields[0] + '" operator="eq" value="' + searchValue + '" />');
fetchXml.push('</filter>');
fetchXml.push('</entity>');
fetchXml.push('</fetch>');
fetchXml = fetchXml.join('');
CrmFetchKit.Fetch(fetchXml).then(function (results) {
/* success handler */
console.log("results: " + JSON.stringify(results, null, 4));
Xrm.Page.getAttribute(targetField).setValue(results[0]['attributes']['productnumber']['value']);
}, onFetchError);
}