Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
eliasmazur
Contributor
Contributor

Resolve promises within paint

Hi,

I'm trying to get the list of sheets from within the "paint" function.  The following code is with the paint function:

define([

  "qlik",

  "jquery",

  'underscore',

], function(qlik,$,_) {

  'use strict';

var me = {

initialProperties : {

....

....

};

me.app = qlik.currApp(this);

me.paint = function($element, layout) {

  var sheets = [];

...

...

...

me.app.getAppObjectList( 'sheet', function(reply){

  var title = "", loc_nb_navlist = "", loc_sheets = [];

  var sortedData = _.sortBy( reply.qAppObjectList.qItems, function ( item ) {

         return item.qData.rank;

    } );

_.each( sortedData, function ( item ) {

     sheets.push( {

       id: item.qInfo.qId,

       name: item.qMeta.title

     } );

   console.log ('sheets array inside: '+sheets);

   qlik.Promise.resolve (sheets);

  } );

}).then(function () {console.log('done get sheets')});

   console.log ('sheets array outside: '+sheets);

...

...

  });

  return me;

});

The console.log for the sheets array inside the call shows the objects fine, but outside the object is empty.  The sheets array are populated inside the call, but become empty outside, so i can't use it.  Any help is appreciated.

Thanks

Elias

2 Replies
ErikWetterberg

Hi Elias,

Do not use the getAppObjectList method in paint. If you instead add appObjectListDef to your properties the framework will handle the asynchronity for you and your paint method will be called when the data is available.

Hope this helps

Erik Wetterberg

eliasmazur
Contributor
Contributor
Author

Hi Erik.

Thanks for the reply.  Do you have an example of adding appObjectListDef to the properties?

Thanks

Elias