0 Replies Latest reply: Jun 30, 2017 6:31 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?