Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
IVAN-FELIPE
Employee
Employee

openApp and getList promises help

Dear colleagues

I'm getting crazy trying to make something that seemed to be simple.

I need to make a loop around all the apps in My Work space. This is OK.

Once I get that list I want to open each an get the list of measures of each app.

Like this:

for (var i = 0;i < appsList.length;i++){

     newApp = qlik.openApp(newAppid);

     newApp.getList( 'MeasureList', function ( data ) {

           MeasureListArray.push(data);

      })

}


It returns a list in a random order, not valid.

I've tried all the combinations of promise codes that I can image without success.


The same problem if I use this in a loop of apps:

newApp.createGenericObject({

qMeasureListDef : {

     qType: "measure",

     qData: {

     title: "/title",

     tags: "/tags",

     expression: "/qMeasure/qDef"

     }

}

}, function(reply){

measJsonArray = reply.qMeasureList.qItems;

});


I can't manage the thread of the code.


Can you send any example of the right way to get the promises for getting the measure list of a list of apps??


Thanks a lot!

7 Replies
ErikWetterberg

Hi,

If your problem is that the order of the measures is wrong, why don't you sort it when you are ready? Of course you can wait until you have the measrelist to open the next app, but that will be slow.

Erik Wetterberg

IVAN-FELIPE
Employee
Employee
Author

The main problem is not estrictly about the order.

The MeasureList doesn't bring info about the app and when I ask for newApp.id I always get the id of the last app.

So after getting the array of MeasureList I can't associate each one to the right app.

Because of that I need the right order inside the getList function... or a trick to get the right app id when I get each MeasureLists

Thanks

ErikWetterberg

HI,

Try something like this:

var measures = [];

appList.forEach(function(appData){

var appid= appData.id, app = qlik.openApp(appid);

app.getList('MeasureList',function(data){

    data.qItems.forEach(function(meas){

       meas.appid= appid;

       measures.push(meas);

    });

});

I haven't tested this, so there will surely be syntax errors.

Erik Wetterberg

IVAN-FELIPE
Employee
Employee
Author

Hi Erik

Not working.

This code returns an error, as 'data' is not a list and does not contains qItems.

Data =

Data_returned.png

I need to open an app, get its MeasureList and then open the next app, managing a promise I supose, but I don't know how to do that.

If I just include...

var measures = [];

appList.forEach(function(appData){

var appid= appData.id, app = qlik.openApp(appid);

app.getList('MeasureList',function(data){   

       measures.push(meas);

  });

});

... I get the MeasureList for the wrong app

Thanks again

ErikWetterberg

HI,

Then try with:

var measures = [];

appList.forEach(function(appData){

var appid= appData.id, app = qlik.openApp(appid);

app.getList('MeasureList',function(data){

    data.qMeasureList.qItems.forEach(function(meas){

       meas.appid= appid;

       measures.push(meas);

    });

});

The entries in the measures array will then have appid for the correct app.

Erik Wetterberg

IVAN-FELIPE
Employee
Employee
Author

Hi again

Sorry for the blast but unfortunately it doesn't work.

I've checked a lot of combinations, tricks...

The code is randomly failing here:

var measures = [];

appList.forEach(function(appData){

var appid= appData.id, app = qlik.openApp(appid);

app.getList('MeasureList',function(data){

    data.qMeasureList.qItems.forEach(function(meas){

       meas.appid= appid;

       measures.push(meas);

      **** in this moment 'appid' can contain a value different than the app associated to 'meas'

    });

});

Thanks

IVAN-FELIPE
Employee
Employee
Author

For those interested in this in the future. Here is a possible solution:

function getNewAppsMeasureList(){

    newMeasOfApps  = [];

    newMeasOfApps2 = [];  


    appList.forEach(function(appData){

      var appid= appData.id, app = qlik.openApp(appid);

      app.getList('MeasureList',measureCallback.bind(app));

     });  

};

function measureCallback(data) {

     data.qMeasureList.qItems.forEach(function(meas){

        meas.appid= this.id;

        console.log(this.id);

        measures.push(meas);

     })

}