Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Iterate over report design with new data
hgk
Hi All,
My report design has lots of tables, images, grids and labels. The tables and grids are populated by the scripted datasource. I pass parameters for labels and image paths. I want to iterate over the report design with new parameters and new scripted datasource in each iteration. The API of the datasource is not going to change in each iteration. Only the data will change in each iteration.
Is this possible? If so, could you please provide a sample for this. I want to write the output of each iteration to a single pdf file.
Thanks for your help,
hgk
Find more posts tagged with
Comments
JasonW
Can you give some more detail on what you need? The design engine api can be used to iterate over a report design, but I am not certain how you want to display this data.
hgk
Jason,
Say I have a report design with a table and 2 labels - one before the table and one after the table. The text for the labels is passed via parameters. The data for the table comes from scripted datasource. I want to create a report with n numbers of tables with label before and after the table.
Sample report:
Data for Owner Brad:
Label
FileName Size Modified Time
Table
abc.doc 10K 8/12/09
def.txt 23K 3/4/09
Brad is the 11th vistor
Label
Data for Owner Tom:
Label
FileName Size Modified Time
Table
power.csv 50K 7/11/09
comp.txt 73K 5/8/09
Tom is the 18th vistor
Label
.
.
.
I want to have only one table and only 2 labels in my report design. I want use it as stamp to create n number of copies with different data. I want to produce a single pdf file.
What API should I use? How do I change datasource and parameters in each iteration?
Thanks,
hgk
JasonW
When you say:
The data for the table comes from scripted datasource
Do you mean each table needs a different datasource? You can use the DE API to copy the elements and paste them, but this can only be done in the beforeFactory prior to running datasources. This means you will have to know how many tables you will need prior to running datasources.
If all your table(s) data was located in one dataset you could add one table put in a group header and group footer label for your two labels. This would give the same appearance as multiple tables. This approach does not use the api.
Jason
hgk
I used table and 2 labels as an example. My report design has lot of tables, labels, grids and images. So group header and group footer do not work.
I think I have to use DE API to copy the elements. If I need to iterate 4 times, then I have to copy and paste the elements 3 times before I call
IRunAndRenderTask task = birtEngine.createRunAndRenderTask(design); ??
The size of my rptdesign is 400KB. Is it possible to create 10 or 20 copies? Is it scalable?
I can use single scripted datasource for all the iterations. I can keep a counter for each iteration and change the underlying data for each iteration.
Can I copy and paste the parameters too using DE API?
If I have a parameter called "InvTimes", I can set its value as below
task.setParameterValue("InvTimes", "4-6-09");
If I copy parameter, I should rename it to say "InvTimes1" and set its value
task.setParameterValue("InvTimes1", "4-7-09");
before I call
task.setRenderOption(options);
task.run();
??
Thanks,
hgk
JasonW
Take a look at this example:
package DEAPI;
import java.util.HashMap;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.core.IDesignElement;
import org.eclipse.birt.report.model.core.DesignElement;
public class ModifyRunningReportCopy {
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2_5_0/birt-runtime-2_5_0/ReportEngine");
config.setLogConfig(null, Level.FINE);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle( );
DesignElement charttocopy = (DesignElement)report.findElement("NewChart").copy();
charttocopy.setName("SecondChart");
//only needed if you do not rename the copy
//report.getModule().makeUniqueName( charttocopy );
report.getBody( ).add( charttocopy.getHandle(report.getModule()) );
//Use this if you want to resave modified example
//report.saveAs("Reports/chartcopy.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", new Integer(3));
task.setParameterValue("Top Count", new Integer(5));
task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/desample/ModifiedTopNPercent.html");
options.setOutputFormat("html");
options.setImageDirectory("images");
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
ModifyRunningReportCopy ex = new ModifyRunningReportCopy( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}