Hi everyone,
We've been getting a couple of questions around emailing of reports.
The actual email action is performed by an event driven rule called "Email Reports Sample". While this rule works as intended, it can use a little tweeking to solve the following 2 issues:
- the attachments are all name "report.<extension>"
- excel files get the extension ".excel"
I'd like to show you how you can change this rule and make sure the proper names and extensions are used.
Create a copy of the rule, and disable the sample.
To make sure we retain the original out of the box sample, we create a copy of it, give it the proper name and description, and disable the sample rule. In my example I did this, and created a new version of the sample rule called "Email Reports-All Filetypes".
For this new rule, I changed the description as well, because the original said it only sent .PDF reports.
Change the Format rule variable.
Next, we need to change the format rule variable. Currently it simply returns the report format as used in the report generation options. This works fine for PDF and XML, but the actual format for Excel reports need to be set to XLS.
In your new rule, navigate to the "Rule Variables" tab and make the following change:
Code snippet:
def rptFormat = @event.get("report/reportFormat");
if ( rptFormat == "Excel" ) {
return "xls"
}
else {
return rptFormat;
}
Ensure that the report gets its proper name.
Finally, we need to make sure the report gets the name that was given to it in the Generate report options. Currently the report attachment is hardcoded to "report.<ext>".
The first step is to create a new Rule level variable, and set it to the actual name of the report:
Code snippet:
return @event.get("report/reportName");
The second step is to change the Email action parameter "mail.attachment.file.name", and change it from report.@format to "@reportName.@format":
Code snippet:
@reportName.@format
Save your work.
Now the rule has been altered and will send the reports with nice names and proper extensions.
Robert