MS CRM 2013 adds version number to WebResources of script type
Asked Answered
R

1

6

I have found strange issue in MS CRM 2013, and since it seems to be by design, I need help to find a way around it.

The issue is it's impossible to call getScript jQuery method from WebResource.

The CRM adds version string to the url, and this causes request fail with error 500.

For example, when I'm trying to call: /Organization/WebResources/Synchronization.js

The CRM turns this request into following: /Organization/WebResources/Synchronization.js?_=1402918931398 and it fails with server error 500.

Here is the sample code I'm using:

var settings = {
    url: "/Organization/WebResources/Synchronization.js",
    dataType: "script",
    success: function (data) {
       console.log("success");
    },
    error: function(jqXHR, textStatus, errorThrown) {
       console.log("error");
    }
};

$.ajax(settings);

Could you please point me, how I can find out when URL is changed?

Release answered 16/6, 2014 at 12:2 Comment(2)
just a note, the number is added in order to force the browser to use the latest version of the webresource, otherwise the browser cache will load old versionsTemporal
In CRM 2013 adding this numbers leads to server error 500.Release
R
4

It turns, that this is jQuery caching feature.

If caching will be turned on in settings object, the issue will disappear. Like this:

var settings = {
    url: "/Organization/WebResources/Synchronization.js",
    cache: true,
    dataType: "script",
    success: function (data) {
       console.log("success");
    },
    error: function(jqXHR, textStatus, errorThrown) {
       console.log("error");
    }
};
Release answered 16/6, 2014 at 12:23 Comment(2)
did you check if with cache: true you get the latest version?Temporal
@GuidoPreite No. I'm relying on cache. This is not good, in general case, but in this particular, could be fine, I don't expect that js file to change. And once again, even if I wanted to get un-cached version, CRM 2013 does not allow me.Release

© 2022 - 2024 — McMap. All rights reserved.