Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set and pass a parameter to a BIRT report created by the BIRT Report Designer through the BIRT API?

I've created a simple report that takes a single parameter. This parameter is used in the query and executes fine when directly executed in the report designer. By the way I'm not using javascript or any scripting for this report. I've seen some people trying to pass parameters using scripts and/or javascripts for answers here, however this is not what I'm doing. I pass all my parameters in through java. Continuing, in this report I'm listing active/inactive items. I pass in an 'N' for listing inactive items and a 'Y' for active items. When I try to pass in a parameter through the API, I always get a list of active items regardless to what I pass in. By the way 'Y' is the default value of the parameter passed in. (I am overriding the defaults in the code below) The problem I'm having is that the report doesn't seem to want to take the parameter I set. Yes the value changes in my variable passed in but the report doesn't reflect the change. My code is below. I've tried to follow the advice of this link and how to set the parameters.

http://www.eclipsezone.com/eclipse/forums/t67723.html

If you go to the link go down to #4 and see the list of tasks to do. This is what I have tried to follow. I feel I may be missing something. If you've got this going could you give me some advice to what I'm missing? Thanks much!

-Dale

    public class ReportGenerator {
        public static void main(String args[]) throws Exception{
        ReportGenerator rg = new ReportGenerator();
        rg.executeReport("N");
        }


        @SuppressWarnings({ "unchecked", "deprecation" })
        public void executeReport(String activeIndicator) throws EngineException {

        IReportEngine engine=null;
        EngineConfig config = null;

        try{
            config = new EngineConfig( );            
            config.setBIRTHome("C:\\birt-rcp-report-designer-3_7_2\\ReportEngine");
            config.setLogConfig("c:/temp/test", Level.FINEST);
            Platform.startup( config );
            IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
            engine = factory.createReportEngine( config );        


            IReportRunnable reportDesign = null;
            reportDesign = engine.openReportDesign("C:\\workspace\\SimpleReport\\ReportTemplates\\ItemListingReport.rptdesign"); 
            IRunAndRenderTask task = engine.createRunAndRenderTask(reportDesign);
            IGetParameterDefinitionTask parameterDefinitionTask = engine.createGetParameterDefinitionTask(reportDesign);
            parameterDefinitionTask.evaluateDefaults();
            HashMap<String, String> params = parameterDefinitionTask.getDefaultValues();
            params.put("aIndicator", activeIndicator);
            parameterDefinitionTask.setParameterValues(params);

            ConnectionHelper connectionHelper = new ConnectionHelper();
            task.getAppContext().put("OdaJDBCDriverPassInConnection", connectionHelper.getConnection());

            PDFRenderOption options = new PDFRenderOption();
            options.setOutputFormat("pdf");
            options.setOutputFileName("C:\\workspace\\SimpleReport\\output\\itemListingReport.pdf");

            task.setRenderOption(options);

            task.run();
            task.close();
            engine.destroy();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            Platform.shutdown();
        }
        }
    }
like image 771
Dale Avatar asked May 25 '12 01:05

Dale


People also ask

What is Birt clause?

BIRT clauses are the directives. When voting, members are only voting on the BIRT clauses, not on their justification in the Whereas clauses. BIRT clauses should not contain any additional explanation or validation, and should be clearly written. When writing a motion, you want to remember these basic principles: 1.


1 Answers

You need to set the parameters on the IRunAndRenderTask:

IRunAndRenderTask task =
    engine.createRunAndRenderTask(reportRunnable);
Map< String, Object > birtParams = ...;
task.setParameterValues( birtParams );
like image 112
Nick Wilson Avatar answered Sep 29 '22 08:09

Nick Wilson