Hello, dear readers! Today, I want to share with you an important use case that might be very useful in your daily work with Jedox. If you are working with Jedox Integrator and Report Designer, sometimes you need to automate processes to make your work easier and faster. One of these tasks might be copying a file from Report Designer, saving it to your file system, and then sending it as an email attachment. I will show you how to do this using a Groovy script. Let’s imagine a scenario where this might be necessary.
Business Scenario
Let’s say you are working in the finance department of a company, and every month you prepare financial reports using Jedox. These reports could be in different formats, like Excel (XLSX), CSV, or even images like PNG. After preparing these reports, you need to send them to your colleagues or your boss for review.
For example, you generate a monthly sales report in Excel format using Report Designer. After generating the report, you need to save a copy of it to a specific folder on your company’s file system, where all monthly reports are stored. But that’s not all – you also need to send this report by email to the head of the sales department.
Unfortunately, due to some limitations, attaching files directly from Report Designer is not possible at the moment. This means that you cannot send the report as an attachment straight from Report Designer. Instead, you must first copy the file to a different location on the file system and then attach it to your email from there.
Instead of doing all these steps manually, you can automate them using a Groovy script in Jedox Integrator. This script will automatically copy the file from Report Designer, save it to your file system, and then send it as an attachment in an email. This saves you time and reduces the chance of human error.
How to Do It
Here is a simple Groovy job script you can use to achieve this:
is = FILE.readBinary("file_source"); // Read the file from the source location in Report Designer
FILE.writeBinary("file_destination", is); // Write the file to the desired destination in the file system
mailer = API.getMailer(); // Initialize the mailer
mailer.addRecipient("[email protected]"); // Add the email recipient
mailer.setSubject("Monthly Sales Report"); // Set the email subject
mailer.setMessage("Dear Team, \nPlease find attached the sales report for this month.\nBest regards."); // Set the email message
mailer.addAttachment("${email_attachment}"); // Attach the file to the email
mailer.send(); // Send the email
Explanation
The prerequisite would be to set up your SMTP server for sending the email. You can find it here:
https://knowledgebase.jedox.com/jedox/maintenance/scheduler-email-settings.htm?Highlight=smtp
https://www.gmass.co/blog/gmail-smtp
- Reading and Writing the File: The script first reads the file from the source location in Report Designer using FILE.readBinary(“file_source”). Then, it writes the file to the destination in your file system using FILE.writeBinary(“file_destination”, is).
- Sending the Email: The script then sets up an email using the API.getMailer() method. It specifies the recipient, subject, and message body. Finally, it attaches the file you saved earlier and sends the email.
Why This is Useful
This process is very useful because it automates a repetitive task. You don’t have to manually download the file from Report Designer, save it to your file system, and then attach it to an email. The Groovy script handles all of this for you in one go. This way, you can focus on more important tasks, knowing that your reports are being sent out correctly and on time.
ETL project can be found here.