Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » How can I pass a parameter to my report?(Trying to set and pass a parameter to a BIRT report created by the BIRT Report Designer through the BIRT API)
How can I pass a parameter to my report? [message #876814] Fri, 25 May 2012 06:10 Go to next message
Dale DeMott is currently offline Dale DeMott
Messages: 1
Registered: May 2012
Junior Member
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. My code is below.

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();
            }
            }
        }

Re: How can I pass a parameter to my report? [message #876933 is a reply to message #876814] Fri, 25 May 2012 10:32 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Dale,

You need to set the parameter on the RunAndRenderTask.

RunAndRenderTask task = engine.createRunAndRenderTask(reportDesign);
task.setParameterValue or task.setParameterValues.

You do not need a parameter definition task to set the parameters.
Generally this task is used to build a custom ui as it gets design
information on report parameters.

Jason


On 5/25/2012 6:10 AM, Dale DeMott wrote:
> RunAndRenderTask task = engine.createRunAndRenderTask(reportDesign);
Previous Topic:BIRT with Multiple Data sets
Next Topic:rap using the birt3.7.1, IReportEngineFactory is null
Goto Forum:
  


Current Time: Sat Aug 23 05:39:16 EDT 2014

Powered by FUDForum. Page generated in 0.02838 seconds