• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Download & Attach Business object crystal reports to an Email

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In our project we are creating some of the reports through SAP Crystal reports. These reports are accessed by their report ids using Business objects (Opendocument API).
In the application after clicking the submit button an email will be sent to the user with all the links to access the excel reports. These links use the Opendocument API and will be redirected through OpenDocument.jsp file to invoke the methods created by business objects.
Bellow is the Java and JSP code for this :
AdpExport.java :

EmailMessage payrollEmail = new EmailMessage();
EmailMessage accountingEmail = new EmailMessage();
payrollEmail.setFrom(EmailConstants.NOREPLY_EMAIL, EmailConstants.PORTAL_SUPPORT_ALIAS);
accountingEmail.setFrom(EmailConstants.NOREPLY_EMAIL, EmailConstants.PORTAL_SUPPORT_ALIAS);

payrollEmail.addTo(emailAddress, emailAddress);
accountingEmail.addTo(emailAddress, emailAddress);

for (String email : AppMgr.getCommissionConfig().getExportPayrollEmails()) {
payrollEmail.addTo(email, email);

for (String email : AppMgr.getCommissionConfig().getExportAccountingEmails()) {
accountingEmail.addTo(email, email);

// Add reports to emails
Map<String, Integer> payrollReports = new HashMap<String, Integer>();
payrollReports.put("Commission Export Pay", Param.Reports.EXPORT_PAY);
payrollReports.put("Payroll Commissions Detail", Param.Reports.DETAIL);
addReportsToMessage(payrollEmail, payrollReports);

Map<String, Integer> accountingReports = new HashMap<String, Integer>();
accountingReports.put("Accounting Charge Off", Param.Reports.CHARGE_OFF);
accountingReports.put("Accounting Accrual File", Param.Reports.ACCRUAL);
accountingReports.put("Payroll Commissions Detail", Param.Reports.DETAIL);
addReportsToMessage(accountingEmail, accountingReports);


private void addReportsToMessage(EmailMessage email, Map<String, Integer> reports) throws ServiceException {
StringBuilder sb = new StringBuilder();
sb.append("Commissions data has been exported.<br /><br />");

for (String key : reports.keySet()) {
sb.append(buildReportListItem(key, getReportUrl(reports.get(key))));


email.setSubject("Commissions export data");

private String buildReportListItem(String name, URL url) {
StringBuilder sb = new StringBuilder();

sb.append("<li><a href='");
sb.append("<a /></li>");

return sb.toString();

private URL getReportUrl(int reportId) throws ServiceException {
try {
DataObject boReport = boService.sdoFindReport(AppMgr.APP_CD, reportId, true);

BOUrl boUrl = BOServices.newUrl(boReport.getString(BOConstants.Params.OPENDOC_URL), boReport.getString(BOConstants.Params.TOKEN));

return new URL(boUrl.getUrl());
} catch (Exception e) {
throw new ServiceException(e);

These are the URLs created by the above code, which are displayed in that Email :
URL is :http://bobi-web1.abcsupply.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=4058889&sOutputFormat=E&token=BOBI-App2.abcsupply.com@4653888JYnKj9AKONRzxcNjF0XDFTL4653507JZJ78OtaLpNyrdmQ4m0IwqV&abcuver=1407176099926
exportPayFile Path is : /opt/IBM/WebSphere/wp_profile/exportPayFile08-04-14_13-14-59-927.xls (The file stored here in this path is Javascript code, its not actual xls file.)

(After clicking on the URLs, user will be redirected to the browser to download the Excel reports. But when session is expired then user will not be able to open or download the excel reports from that email URL links.)

Bellow is the OpenDocument.jsp file which is redirected when the java code is executed :
<script type="text/javascript" src="../../OpenDocument/1210291354/OpenDocument/js/shared_caf_utils.js"></script>
<script type="text/javascript" src="../../OpenDocument/1210291354/OpenDocument/js/openDocumentUtils.js"></script>
<script type="text/javascript">
function isApplication() {
// Try to find the specifc callback up the DOM tree
var invokeOpendocActionCallback;
try {
var appKindCallback = businessobjects.opendocument.findCallback("caf_callback_getAppKind");
var fromAppKind = null;
if (appKindCallback != null) {
fromAppKind = appKindCallback();

invokeOpendocActionCallback = businessobjects.opendocument.findCallback("caf_callback_opendoc");

catch(e) {
// Exception is due to trying to access members in parent frames that are in different domains
// Ignore exception object as it has no meaning in Firefox
invokeOpendocActionCallback = null;

var name="";
// OpenDoc invoked from apps other than InfoView (e.g. CMC) is considered standalone
if (invokeOpendocActionCallback == null) {

//check if we are already in an Opendoc window
var mywin=businessobjects.webutil.caf.getAppropriateOpenDocContainerFrame();

if ("OpenDocument" == mywin.appKind) {
//if appKind (or ses, or service, etc) is defined in the top window, then we are in opendoc already
//so we dont need to go to the logon page
//we need to get the enterprise session and other parameters from the top window,
//and we want to make sure that we load up in the top window

//if we want to open a new window, this variable will be changed to the name of the new window
name = mywin.name;


} else {

<form method="POST" action="../../OpenDocument/1210291354/OpenDocument/opendoc/openDocument.jsp" target="">
<input type="hidden" name="isApplication" id="isApplication">
<input type="hidden" name="appKind" id="appKind">
<input type='hidden' name="iDocID" value="4058889" >
<input type='hidden' name="sOutputFormat" value="E" >
<input type='hidden' name="token" value="BOBI-App1.abcsupply.com@4637918J6uZUQcevFNS23yjujbc4iv4636425JQY8qTLJ3SO8EGERvu1eVVb" >
<input type='hidden' name="abcuver" value="1406903836194" >


<script type="text/javascript">

I need to modify the code, so that the email is sent without the links but with the excel reports attached to it.
So in Java, i need to download the excel reports first and then attach them to the email.
So bellow is the code which I had modified :
AdpExport.java :

File exportPayFile = null;
File detailFile = null;
URL url = null;
// Add reports to emails
Map<String, Integer> payrollReports = new HashMap<String, Integer>();
payrollReports.put("Commission Export Pay", Param.Reports.EXPORT_PAY);
payrollReports.put("Payroll Commissions Detail", Param.Reports.DETAIL);
addReportsToMessage(payrollEmail, payrollReports);

for (String key : payrollReports.keySet()) {
url = getReportUrl(payrollReports.get(key));
if(payrollReports.get(key) == Param.Reports.EXPORT_PAY){
exportPayFile = new File("exportPayFile"+dateFmt.format(Calendar.getInstance().getTime()) + ".xls");
FileUtils.copyURLToFile(url, exportPayFile);
payrollEmail.addAttachment("Commission Export Pay", "EXPORT_PAY", exportPayFile.getAbsolutePath());
} else {
detailFile = new File("detailFile"+dateFmt.format(Calendar.getInstance().getTime()) + ".xls");
FileUtils.copyURLToFile(url, detailFile);
payrollEmail.addAttachment("Payroll Commissions Detail", "DETAIL", detailFile.getAbsolutePath());
if(!exportPayFile.isFile() && !detailFile.isFile()){
After above modification I was able to download the file from the URL created, but it was only the javascript file(as shown above).
Can anybody please tell me, how I can download the excel file created by Business objects or crystal reports ?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic