Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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);
});
});
});
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);
Hi,
Any errors in the browser console? Have you tried catching errors from the exportImg call?
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
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.
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
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);
This worked like a charm, thank you very much for your help!