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: 
HeinriG
Contributor III
Contributor III

Exporting multiple images using exportImg in forEach() only prints some of the images

Hi,

I am trying to export multiple images from a list (array) of object ids using forEach and exportImg. The function iterates through all ids but only seems to return links for some of the object ids. It also seems like it is either 1 or 2 less than the total amount requested. Any help would be much appreciated. For what it's worth, the loop runs inside of an onClick event attached to a button.

Code:

exportIdList.forEach((id, key) => {
     app.visualization.get(id).then(function(vis){
                      vis.exportImg(settings).then(function (link) {
                                    console.log(link);
                       });
      });
});

Labels (2)
1 Solution

Accepted Solutions
ErikWetterberg

You could fetch them one by one something like this (I haven't actually tried this, so there might be errors in the code):

function exportList(array, pos){

if(pos < array.length){

     app.visualization.get(array[pos]).then(function(vis){
                      vis.exportImg(settings).then(function (link) {
                                    console.log(link);

                                    exportList(array, pos+1);
                       });
      });

}
}

exportList(exportIdList,0);

View solution in original post

6 Replies
ErikWetterberg

Hi,

Any errors in the browser console? Have you tried catching errors from the exportImg call?

HeinriG
Contributor III
Contributor III
Author

Hi,

Thank you for the quick reply. No errors that I could see, even using try/catch it didn't pick up any errors. Some of the images just don't get exported.

Regards,

Heinri

ErikWetterberg

And different charts failing each time?

You could try fetching and printing them one by one instead of in paralell. I don't have much experience with the printing service, but I assume there is a log you could look at.

HeinriG
Contributor III
Contributor III
Author

Hi,

Sometimes different charts fail to print, it is quite inconsistent, but it generally still prints 1 or 2 less than my selection.

How would I go about fetching them one by one? I've tried the setTimeout() method to spread the calls out with no luck. 

I've been looking for a log, I can't seem to find it but I'm still searching.

Regards,

Heinri

ErikWetterberg

You could fetch them one by one something like this (I haven't actually tried this, so there might be errors in the code):

function exportList(array, pos){

if(pos < array.length){

     app.visualization.get(array[pos]).then(function(vis){
                      vis.exportImg(settings).then(function (link) {
                                    console.log(link);

                                    exportList(array, pos+1);
                       });
      });

}
}

exportList(exportIdList,0);

HeinriG
Contributor III
Contributor III
Author

This worked like a charm, thank you very much for your help!