Hi all. I recently discovered a rather nasty caching bug in the turbo forms rendering engine. After publishing changes to a form, if a user has the form cached in their browser, the updated form will render with the cached scripts. This only happens on the first load, on subsequent loads the form will render with the updated scripts. I have verified this issue in CRM 2016 Online (v8.2) and on premise (v8.0, v8.0.1, v8.1, and v8.2).
This is a rather nasty bug because it only happens after deployments, only for cached pages, only on the initial load, and it can manifest itself in numerous ways. When the script is not in sync with the form, dependent form objects or fields may be missing and cause errors. Additionally, users will not see the updated form logic. This results in wasted QA and UAT cycles plagued with bugs that cannot be reproduced. This will also have developers' heads spinning. It has taken me 6 months to identify and resolve this issue. I can only imagine how many project hours this has wasted. It is for that reason that I am posting this, to hopefully save the sanity of other Dynamics users.
Steps to reproduce:
1. Add the following script on form-load
alert('Version 1');
2. Publish the script and the form.
3. Navigate to the form and receive the prompt: 'Version 1'
4. Update the form script to:
alert('Version 2');
Optionally, update the form layout
5. Publish the script and the form.
6. Navigate to the form or refresh the page. You will receive the prompt: 'Version 1'. If you made a layout change to the form, you will see the updated layout.
If you navigate to the form or refresh the page again, you will receive the prompt: 'Version 2'. So after publishing script and form changes, the updated form loaded with the cached scripts. Again, this only happens on the first load.
Hopefully Microsoft will realize that this issue is causing severe implementation problems and will prioritize the resolution (and offer me a job). Until then, I developed the following solution. The following code checks for cached scripts and, if it finds one, it reloads the page. You can add this to form-load events to prevent this issue. It would probably be overkill to add this to every customized form with script, but adding this to your primary forms may save you a few headaches. It works by checking the currently loaded scripts against the current web resource GUID. The CRM platform uses this GUID to version the web resources. (You will need to also add a reference to jQuery, if you haven't already.)
var CurrentVersionString = encodeURIComponent(window.parent.WEB_RESOURCE_ORG_VERSION_NUMBER).toUpperCase();
console.log('Current WR Version: ' + CurrentVersionString);
var _formScripts = $('script').each(function (_index, _script) {
if (_script.src) {
var _src = _script.src.toUpperCase();
if (_src.indexOf('WEBRESOURCES') >= 0 && _src.indexOf(CurrentVersionString) < 0) {
window.parent.parent.location.reload();
}
}
});
*This post is locked for comments