<p>Please help me with the dynamic table creation.</p>
<p> </p>
<p>Please note that, this is a table creation and not modification of existing table.</p>
<p> </p>
<p>I came across multiple question while trying this.</p>
<p> </p>
<p>1. Below 2 lines of code for fetching already created datasource did not work in my beforeFactory script.</p>
<p>As a workaround, I created a new datasource in the script with hardcoded values. (See full script below)</p>
<p> </p>
<div>//var dsrc = reportContext.getDesignHandle().getDesign().findDataSource("DataSource");</div>
<div>//var dsrc = reportContext.getDesignHandle().findDataSource("DataSource");</div>
<div> </div>
<div>Could you please point out what is wrong here? Both above statements did not work.</div>
<div> </div>
<div>2. Also, in my below script, I am doing string replacement in SQL query instead of using parameter definition. Could you please provide me with the example of datasource with parameter definition created dynamically.(See full script below).</div>
<p> </p>
<div> </div>
<div>3. In my beforeFactory script I am adding a table dynamically, but it is not shown in the generated report nor any exception is thrown.(See full script below)</div>
<div> </div>
<div> </div>
<p>Below is my beforeFactory script:</p>
<p> </p>
<div>importPackage( Packages.org.eclipse.birt.report.model.api );</div>
<div>importPackage(Packages.java.lang);</div>
<div>importPackage(Packages.java.util);</div>
<div>importPackage(Packages.org.eclipse.birt.data.engine.api);</div>
<div>importPackage(Packages.org.eclipse.birt.report.model.api);</div>
<div>importPackage(Packages.org.eclipse.birt.data.engine.api.querydefn);</div>
<div>importPackage(Packages.org.eclipse.birt.data.engine.core);</div>
<div>importPackage(Packages.org.eclipse.birt.core.data);</div>
<div>importPackage(Packages.org.eclipse.birt.report.model.elements);</div>
<div>importPackage(Packages.org.eclipse.birt.report.model.api.elements);</div>
<div>importPackage( Packages.org.eclipse.birt.report.model.api );</div>
<div> </div>
<div> </div>
<div> </div>
<div>/*************Create table dynamically***********/</div>
<div> </div>
<div>//var dsrc = reportContext.getDesignHandle().getDesign().findDataSource("DataSource");</div>
<div>
<div>//var dsrc = reportContext.getDesignHandle().findDataSource("DataSource");</div>
<div> </div>
<div> </div>
</div>
<div>var dsrc = elementFactory.newOdaDataSource( "DataSource1", "org.eclipse.birt.report.data.oda.jdbc" );</div>
<div>dsrc.setProperty( "odaURL", "jdbc:oracle:thin:
@ihost288:1521:ASCS" );</div>
<div>dsrc.setProperty( "odaDriverClass", "oracle.jdbc.driver.OracleDriver");</div>
<div>dsrc.setProperty( "odaUser","user1" );</div>
<div>dsrc.setProperty( "odaPassword", "pass1" );</div>
<div>reportContext.getDesignHandle().getDataSources().add( dsrc );</div>
<div> </div>
<div>var dset = reportContext.getDesignHandle().findDataSet("DataSet1");</div>
<div> </div>
<div>
<div>var projList = reportContext.getParameterValue("ProjectType");</div>
<div> </div>
<div> </div>
</div>
<div>for(iNum = 1; iNum <=projList.length ; iNum++) {</div>
<div>var odaDataSet = elementFactory.newOdaDataSet( "TestDataSet" + iNum , "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");</div>
<div>odaDataSet.setDataSource( dsrc.getName( ) );</div>
<div>odaDataSet.setQueryText( dset.getQueryText().replace("****",projList[iNum-1])); </div>
<div> </div>
<div>reportContext.getDesignHandle().getDataSets( ).add( odaDataSet );</div>
<div> </div>
<div>//Table created</div>
<div>dynamicTable = elementFactory.newTableItem("Table"+iNum);</div>
<div>dynamicTable.setWidth("100%");</div>
<div>dynamicTable.setDataSet(odaDataSet);</div>
<div> </div>
<div>reportContext.getDesignHandle().getBody().add(dynamicTable);</div>
<div>}</div>
<div> </div>