Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
HeinriG
New 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 (4)
1 Solution

Accepted Solutions
ErikWetterberg
Honored Contributor

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

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);

6 Replies
ErikWetterberg
Honored Contributor

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

Hi,

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

HeinriG
New Contributor III

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

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
Honored Contributor

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

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
New Contributor III

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

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
Honored Contributor

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

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);

Highlighted
HeinriG
New Contributor III

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

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