Issue with Duplicate Files in Multiple Downloads Using JavaScript in Mendix

0
I'm working on downloading multiple files using JavaScript in Mendix. While I can download the files successfully, I'm facing an issue: when initiating multiple downloads, each new download includes the files from the previous downloads along with the current files. This causes duplicate files to overwrite the previous ones when extracted. How can I resolve this issue? import "mx-global"; import { Big } from "big.js";   // BEGIN EXTRA CODE export function downloadFileWithDelay(fileDoc) { if (fileDoc.get("HasContents")) { console.dir(fileDoc); const url = "/file?guid=" + fileDoc.getGuid() + "&target=internal"; const name = fileDoc.get("Name"); const message = "file with url:" + url + " and name " + name;   console.debug("found " + message); const a = document.createElement('a'); a.href = url; a.target = '_parent';   if ('download' in a) { a.download = name; (document.body || document.documentElement).appendChild(a);   if (a.click) { console.debug("starting download " + message); a.click(); } a.parentNode.removeChild(a); } } } // END EXTRA CODE   /** * @param {MxObject[]} fileDocumentList * @returns {Promise.<void>} */ export async function Copy_JSA_MultipleFileDownload(fileDocumentList) { // BEGIN USER CODE   fileDocumentList.forEach(fileDoc => { if (window.document.documentMode) { // setTimeout(() => { downloadFileWithDelay(fileDoc); }, 500); } else { downloadFileWithDelay(fileDoc); }   }) // END USER CODE }  
asked
1 answers
0

Hi Kaveri,

 

your code looks a bit like my code but also a bit different. Did you try the JS action I added as an answer here. Has been working for quite some time in our app:

 

https://community.mendix.com/link/space/studio-pro/questions/119569

 

 

answered