3 Replies Latest reply: Feb 26, 2018 7:16 AM by Richard Bartley RSS

    Sequencing issues with app.getObject

    Richard Bartley

      Dear all,

       

      I am having some sequencing issues when working within a mashup and when trying to re-use an object to display a different chart and download the data from that chart.  Most of the time it worked fine, but sometimes it returned an error VM5616 require.js:44 TypeError: Cannot read property 'then' of undefined.  So, I am now trying to force the getObject call to be synchronous by calling a function  setCurrentPriceChart which is not resolved until the app.getObject call has completed.

      function setCurrentPriceChart(chartID)

      function setCurrentPriceChart(chartID)
      {
        var deferred = $.Deferred();
        currentPriceChart = app.getObject('chartPrice', chartID).then(function()
        {
        deferred.resolve();
        });
        return deferred;
      }
      

       

      I have a button called cmdPrice which I am using to download the data associated with the chart (see below), but when I write the currentPriceChart object details to the console the value is undefined and an error is returned: VM5616 require.js:44 TypeError: Cannot read property 'then' of undefined at the line var table = new qlik.table(model);

       

      $('#cmdPrice').on('click', function() {
        console.log('cmdPrice clicked currentPriceChart=',currentPriceChart);
      
        if(typeof currentPriceChart.value!=="undefined")
        {
        //console.log('currentPriceChart.value',currentPriceChart.value);
        currentPriceChart.then(function(model){
        var table = new qlik.table(model);
        return table.exportData({download: true})
        })
      
        }
        else
        {
        console.log('setCurrentPriceChart strSelectedPageButton=',strSelectedPageButton);
        promise = setCurrentPriceChart(strSelectedPageButton);
        $.when(promise).then(function()
        {
        console.log('currentPriceChart=',currentPriceChart);
        currentPriceChart.then(function(model){
        var table = new qlik.table(model);
        return table.exportData({download: true})
        })
      
        });
      
      
        }
      
         
         
        });
      

       

      Does anyone have any ideas?

        • Re: Sequencing issues with app.getObject
          kumar parth

          Hi Richard,

           

          I encountered the same issue of sequencing in app.getObject.. Would be great if you could provide the solution..Its been a year you reported this issue and I guess you already might have resolved it...

            • Re: Sequencing issues with app.getObject
              Richard Bartley

              Hi Kumar ,

               

              In the end I didn't have enough time to investigate this fully.  The following code should work though:

              app.getObject('chartPriceEvolution','KxYbfG').then( function( vizModel ) {  
              $('#cmdPriceAllPeriods').prop('onclick',null).off('click');
              $('#cmdPriceAllPeriods').on('click', function() 
              {  
              vizModel.exportData().then(function( reply ) {  
              var url = 'http://' + config.host +'/auth'+reply.qUrl;
              window.open(url);
              });  
              }); 
              });
              
              
              • Re: Sequencing issues with app.getObject
                Richard Bartley

                Hi Kumar,

                 

                I just looked into this again and have a solution:

                 

                function setCurrentPriceChart(chartID)  
                {  
                  console.log('setCurrentPriceChart ',chartID);
                  var deferred = $.Deferred();  
                  currentPriceChart = app.getObject('chartPrice', chartID).then(function(vizModel)  
                  {  
                  deferred.resolve(); 
                  
                  $('#cmdPrice').on('click', function() {  
                vizModel.exportData().then(function( reply ) {  
                console.log('reply=',reply);
                var url = 'http://' + config.host +'/auth'+reply.qUrl;
                //console.log('qUrlModified', url); 
                window.open(url);
                
                });  
                  }); 
                  });  
                  return deferred;  
                } 
                

                 

                Notice that the qURL has moved from reply.result.qURL to reply.qURL.