2 Replies Latest reply: Aug 8, 2017 10:30 AM by Elias Mazur RSS

    Resolve promises within paint

    Elias Mazur

      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