HowTo Correct Inconsistent Tasks Loading
On the initial load there is often a limited subset of tasks:
If the user refreshes, F5, the Tasks list then populates as expected:
Any recommendations on how to resolve this inconsistency is greatly appreciated.
When this occurs, no errors are dumped to the Dev Console.
Portal Version: 8.2.2.2012
My apologies if my search skills are weak and I missed a similar post.
Best Answer
-
Geoff_Ross Cireson Consultant O.G.Hi All,
This is the code i use to load external scripts into custom.js rather than putting code directly into it./* ----------------------------------------------- */ /* ----------------- Script Loader --------------- */ /* ----------------------------------------------- */ // This helps with loading scripts and debugging // Pass in the path of the js file and an array of url segments on which to run this code // EG loadScript("/CustomSpace/CustomExtension/CustomExtension.js",["ServiceRequest","Incident"]); var loadScript = function (path,urls) { urls.forEach(function(url){ if(window.location.href.indexOf(url) !== -1){ // Verify we are on the valid page var result = $.Deferred(), script = document.createElement("script"); script.async = "async"; script.type = "text/javascript"; script.src = path; script.onload = script.onreadystatechange = function(_, isAbort) { if (!script.readyState || /loaded|complete/.test(script.readyState)) { if (isAbort) result.reject(); else result.resolve(); } }; script.onerror = function () { result.reject(); }; $("head")[0].appendChild(script); console.log("Loaded " + path) return result.promise(); } }) }; /* ----------------------------------------------- */ /* --------------- END Script Loader ------------- */ /* ----------------------------------------------- */
With this example of how to use it:loadScript("/CustomSpace/RDPTask/RDPTask.js",["/Incident/","/ChangeRequest/"]);
This brings a number of advantages over code directly into custom.js- custom.js does not end up 1,000s of lines long
- Customisations can be turned off and on by commenting / commenting the line above
- The code is only loaded on relevant pages as per the 'urls' parameter which avoids taking time to download files that add no value to the current page or could cause problems on current page
- Debugging is still possible unlike with $.getScript()
Geoff6
Answers
I can't tell you exactly what is causing this but I can tell you that the difference between the two lists is that the first is just the Out of Box tasks and the second contains custom tasks. So the issue is something around how you custom code is getting loaded because it is failing to do so on initial load.
Depending on how you are doing this there could be a number of reasons why.
Does that help point you in the right direction at all?
Geoff
Hi,
several weeks ago I came across an alternate possibility to load the js files - I am not sure if this solves the problem - and maybe you have already tested this ...
This is the code i use to load external scripts into custom.js rather than putting code directly into it.
With this example of how to use it:
This brings a number of advantages over code directly into custom.js
- custom.js does not end up 1,000s of lines long
- Customisations can be turned off and on by commenting / commenting the line above
- The code is only loaded on relevant pages as per the 'urls' parameter which avoids taking time to download files that add no value to the current page or could cause problems on current page
- Debugging is still possible unlike with $.getScript()
Hope this helpsGeoff
Do you have an example of how to code it for multiple script calls?
Sorry, I am still learning.
Jeff