4
votes

I have several Birt Reports that I am trying to set up to run on a cron job that will email pdfs of the reports every morning. Everything is working fine as far as the generation and emailing goes; the only issue I am stuck with is this: if there is nothing to report, a pdf with just the report title is generated and emailed (a blank report, basically). I'd like to stop this report from being generated at all, so i can skip the emailing, if the pdf file does not exist.

I have been all over Google for two days now, and the closest I can find is this: http://www.eclipse.org/forums/index.php/t/458779/ in which someone was trying to solve a similar problem and received a push in the right direction, but not a complete solution.

It appears as if this can be done during the beforerender script... but how? I know I need to:

  1. set a persistent global variable in the oncreate if there is indeed data to report.

  2. get the persistent global variable in the beforerender script.

  3. send the magic don't generate report command.

I'm doing all of generating and emailing from a php script, not Java, so I can't send commands like IEngineTask.cancel() (or can I???)

Yes, I know I can make a row in the report that says "No data to report", but that's not what my users want.

And yes, I could query the database outside of the report to determine if there is valid data to report or not, but i'd prefer not to.

And maybe I could even open and read the pdf, programmatically to see if there is anything there, but that sounds like more of a hassle than it's worth...

So, how do I do this?

Thanks.

1

1 Answers

1
votes

My answer is a little bit late, but I'm doing it like this in a framework that is working for hundreds of reports, probably it could be simplified for a single report: Note that all the code is written from memory (not copied from our framework), so maybe it contains some errors.

Add an external Javascript file myframework.js to your report.

In this file, define an object myframework like this:

if (myframework == undefined) {
    myframework = {
        dataFound: false,
        afterReport: function() {
            // Write it to the appContext.
            // Using Java, you could read it after the
            // runAndRenderTask is done.
            reportContext.getAppContext().put("dataFound", this.dataFound);
            // But since you probably cannot the context
            // (don't like coding Java?), the report has to
            // tell it to he world some other way...
            var txt = "dataFound=" + (dataFound? "true": "false");
            var fw = new java.io.FileWriter("c:\\reportcontext.out");
            fw.write(txt);
            fw.close();
        }
    };
}

Add the JS file to your report's resources.

In your report, at a place where you decide that the report has found something (e.g. typically in a data set's onFetch event), tell the framework so by calling

myframework.dataFound = true;

In the reports's afterFactory or afterRender event, call

myframework.afterReport();

Then your report should create an output file c:\reportcontext.out which contains the information you need.