Every day at Deft Flux, we are mapping unique paths from problem to solution, and we like to share them with you from time to time. Today, our question is a common one — “How can I automatically run and e-mail a Crystal Report?”
Let’s consider this case where you want to schedule a report to be run and delivered to some users via e-mail. For our readers who use Epicor, scheduling a report is as simple as setting up the system agent, loading the report, selecting the schedule, and pressing submit. For the e-mailing, Epicor offers a module called Advanced Print Management (APM) and it would be the simplest way to e-mail reports in Epicor.
It may be, however, that your company does not have a license for APM or you may need to report on data outside of Epicor — perhaps another relational database or an XML file. In either case, you want to e-mail the report to a set of users. Let us use the external XML file as our example. Let us say that another program drops a sequentially numbered XML file into a given directory on the network, and each time it does, you want to use that file to run a Crystal Report and e-mail the output to the user(s). To do this, we could take the following approach:
- Create a User Defined Code in Epicor (or other ERP system) to store the e-mail addresses to which this report should be sent. That makes it easy to change them later on.
- Create a SQLServer Integration Services (SSIS) project to run the report and e-mail it.
- At the first step in the SSIS work flow, go to the database and the User Defined Codes table to pick up the list of e-mail addresses to which this report should be sent.
- Use an SSIS “For Each” loop to detect and process the XML file(s) in question.
- Inside the for each loop:
- Create a .NET program to run the Crystal Report, create the report from the XML file, and then export the output to a PDF file.
- E-mail the PDF to the addresses we found at step #3.
- Archive or delete the XML file.
Here we have a common business problem with an elegant solution, one that is quick and easy to implement, with reduced future maintenance. We shall leave the details of the implementation up to your specific environment, but when you need assistance, we are here to help.