Excel Exporter able to download multiple documents with one microflow

0
Hi everyone, I want to be able to download multiple excel files with the click of a button. When the microflow is called, multiple documents are generated and are supposed to download, but only the last file in line is downloaded. Does anyone know how to resolve this? Thanks, Jon
asked
1 answers
1

Hi Jonathan,

It is not possible by default to download multiple documents. You can achieve this by zipping the files and than download the zip.

If not already available then create a java action called ‘ZipDocuments’ and add parameters as ‘ZipFileInput’ and ListOfDocuments’ and use below java code in your java action using eclipse.

 

@java.lang.Override
public java.lang.Boolean executeAction() throws Exception
{
	this.ZipFileInput = __ZipFileInput == null ? null : system.proxies.FileDocument.initialize(getContext(), __ZipFileInput);

	this.ListOfDocument = new java.util.ArrayList<system.proxies.FileDocument>();
	if (__ListOfDocument != null)
		for (IMendixObject __ListOfDocumentElement : __ListOfDocument)
				this.ListOfDocument.add(system.proxies.FileDocument.initialize(getContext(), __ListOfDocumentElement));

	// BEGIN USER CODE
	File tempFile = File.createTempFile("zipfile", "tmp");
	ZipOutputStream zipfile = new ZipOutputStream(new FileOutputStream(tempFile));

	List<String> fileList = new ArrayList<String>();
	for (system.proxies.FileDocument file : ListOfDocument) {
		String fileName = file.getName();
		if (fileList.contains(fileName)) fileName = file.getMendixObject().getId().toLong() + " " + fileName;
		fileList.add(fileName);
		zipfile.putNextEntry(new ZipEntry(fileName));
		InputStream inputStream = Core.getFileDocumentContent(getContext(), file.getMendixObject());
		IOUtils.copy(inputStream, zipfile);
		zipfile.closeEntry();
	}
	zipfile.close();
		
	InputStream zipInputStream = new FileInputStream(tempFile);
	Core.storeFileDocumentContent(this.getContext(), ZipFileInput.getMendixObject(), zipInputStream);
	tempFile.delete();
		
    return true;		
	// END USER CODE
}

 

Hope this helps!

answered