0

I am working on editable grid for MS CRM 2016. I made HTML web resource that retrieves records from CRM system and displays them in table that is dynamically created in the generateTable() function. This can take a bit long, and I would like to display loading gif while generateTable() function is doing it's thing. I am using XrmServiceToolkit for retrieving, deleting, updating and creating new records.

loadingScreen() function hides div that contanis the table and shows the div with gif image in it... stopLoadingScreen() does the opposite.

My code looks like this, but the loading gif is not showing at all...

function onLoad(){
            loadingScreen();
            try{
                generateTable();
            }
            catch(err){
                alert(err.toString());
            } finally {
                stopLoadingScreen();
            }
        }

Is there something that I am missing? Are there any solutions to this (maybe with jQuery or smth)?

ddelic
  • 89
  • 13

1 Answers1

0

Assuming generateTable() is an async function, loadingScreen and stopLoadingScreen functions get called one after the other in quick succession, so you won't really see you animated gif.

If generateTable(); function is what is using XrmServiceToolkit method to retrieve records, your stopLoadingScreen(); function should be inside a callback, handle your try catches inside the generateTable function.

function onLoad() {
  loadingScreen();
  generateTable(function() {
      stopLoadingScreen();
  });
}
dynamicallyCRM
  • 2,980
  • 11
  • 16
  • Using this approach indeed shows the gif, but stopLoadingScreen() function doesn't get executed. – ddelic Jun 09 '16 at 08:38
  • Do I have to modify generateTable(); function declaration in order for this to work? – ddelic Jun 09 '16 at 08:52
  • Yes, you would need to pass on a callback to the generateTable function, so your function should look something like so: function generateTable(callback) { //after the xrmservicetoolkit call if(callback && typeof(callback) === "function") callback(); } – dynamicallyCRM Jun 09 '16 at 15:36
  • Hmm. I am getting really frustrated by this. The gif still isn't showing. I am guessing that CRM is displaying web resources once they are fully loaded so the loading screen doesn't even have time to be displayed... – ddelic Jun 10 '16 at 07:31
  • Can you post your code? The more we see the better we can help. – dynamicallyCRM Jun 10 '16 at 16:32
  • Every XrmServiceToolKit method has a callback that you need to use, this will ensure your stop loading function runs after XrmSeriviceToolkit has performed its call, for example, loadingScreen(); XrmServiceToolkit.Soap.Retrieve(entityName, entityId, cols, function(response) { stopLoadingScreen(); }); – dynamicallyCRM Jun 13 '16 at 15:15