You are not logged in.
Pages: 1
Hi,
Is there a way to setup file name when exporting a report (except exporting it into a TeamSpace)?
In a script report I'd like to construct it from some parameters + report name etc.
cheers,
Karolina
Offline
Hi Karolina,
we already have that one on the todo list but there is currently no nice way of doing this. What is possible is to hook into the
export process and override the HTTP Headers which allows you to set the file name for download. The corresponding hook is
net.datenwerke.rs.core.server.reportexport.hooks.ReportExportAdjustHttpHeaderHook
Anyhow. I'll give the ticket a +1.
Cheers
Arno
Offline
Hi Arno,
Thank you for giving the +1 for the ticket.
To be honest, I can't find a way to get parameters' values of the exported report neither through Report object, nor by CompiledReport... any hint?
Cheers,
Karolina
Last edited by karolina (2015-01-27 17:50:59)
Offline
Hi Karolina,
the interface isn't really great there: You have to loop over all ParameterInstances and find the one with the matching key:
package tmp
import java.text.SimpleDateFormat
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import net.datenwerke.rs.core.server.reportexport.hooks.ReportExportAdjustHttpHeaderHook
import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report
def HOOK_NAME = "ADJUST_DL_FNAME"
def makeExportFilename = { Report report ->
String reportName = report.getName();
import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance;
for(ParameterInstance pi : report.getParameterInstances()){
if("P_CUSTNUM".equals(pi.getKey())){
System.out.println(pi.getSelectedValue(null));
}
}
return reportName.replaceAll("[^a-zA-ZüÜöÖäÄß\\(\\)\\[\\] \\-\\.0-9]+","_");
}
def callback = [
adjustHeaders : { Report report, CompiledReport executedReport, HttpServletRequest req, HttpServletResponse resp ->
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
resp.setHeader("Content-Disposition", "attachement; filename=\"" + format.format(Calendar.getInstance().getTime()) + "_" + makeExportFilename(report)+"."+ executedReport.getFileExtension() +"\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
] as ReportExportAdjustHttpHeaderHook
GLOBALS.services.callbackRegistry.attachHook(HOOK_NAME, ReportExportAdjustHttpHeaderHook.class, callback)
Pages: 1