Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
rbartley
Specialist II
Specialist II

Sequencing issues with app.getObject

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?

1 Solution

Accepted Solutions
rbartley
Specialist II
Specialist II
Author

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.

View solution in original post

3 Replies
Anonymous
Not applicable

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...

rbartley
Specialist II
Specialist II
Author

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);

}); 

});

});

rbartley
Specialist II
Specialist II
Author

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.