Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

eliasmazur
New 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
erik_wetterberg
Honored Contributor

Re: Resolve promises within paint

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

Erik Wetterberg
https://extendingqlik.upper88.com/
eliasmazur
New Contributor

Re: Resolve promises within paint

Hi Erik.

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

Thanks

Elias

Community Browser