Home
Analytics
Create datasets with javascript (birt)
ss_88_ss
I would like to create datasets on demand by passing parameters to the report which are the names of the files that should be queried in order to get the right columns and data in the report, i was thinking of something like editing this.queryText attribute where "this" represents the dataset but it's not yet created then.
Could we create the dataset and then access it to edit the queryText attribute?
If it is possible how ?
Many thanks.
Find more posts tagged with
Comments
kclark
If I understand your question correctly you should be able to use the value of the parameter when you're creating that dataset in script by passing it using params["MyParam"] in lieu of the static text that you would normally provide.<br />
<br />
So you could do something like<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( params["paramDataSrc"] );
odaDataSource.addPublicProperty( "odaURL", dsrc.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass", dsrc.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser", dsrc.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );
</pre>
<br />
I attached a tweaked version of <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1542-data-engine-api-to-check-data-set-values/'>this
devshare</a><br />
<br />
When it prompts you for the data source URL use<br />
<br />
org.eclipse.birt.report.data.oda.jdbc
ss_88_ss
thanks for the answer<br />
<br />
In your attached example datasets are already created i want to create them (from a flat file datasource )and specify the query to get the right columns in the report context with javascript<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="110225" data-time="1349705093" data-date="08 October 2012 - 07:04 AM"><p>
If I understand your question correctly you should be able to use the value of the parameter when you're creating that dataset in script by passing it using params["MyParam"] in lieu of the static text that you would normally provide.<br />
<br />
So you could do something like<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( params["paramDataSrc"] );
odaDataSource.addPublicProperty( "odaURL", dsrc.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass", dsrc.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser", dsrc.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );
</pre>
<br />
I attached a tweaked version of <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1542-data-engine-api-to-check-data-set-values/'>this
devshare</a><br />
<br />
When it prompts you for the data source URL use<br />
<br />
org.eclipse.birt.report.data.oda.jdbc<br /></p></blockquote>
johnw
What your looking to do is fairly complex. Its a much easier thing to do using a Java event handler as opposed to trying to do it in Javascript and having to worry about assigning the correct classes to vars, and having to look up which classes have what properties and methods.
With that said, the basic idea can be done in the beforeFactory, and you will create a new OdaDataSetHandle object using the type of the oda plugin. I have an example here:
http://digiassn.blogspot.com/2011/01/birt-dynamically-adding-data-set-to.html
In this case it is using a JDBC dataset, but you can change the type to flatfile. You wont need to set the queryText as that is not applicable for the flat file data source. Best thing to do to figure out what properties you will need to set to map columns is to create a basic BIRT report that connects to one of your flat files, and open the XML and check out the data set section to see what properties are set to what values. Then using my example above, set those properties. When finished, you can export that class as a jar, and on the report body, set the Event Handler class to your newly created class. If you don't want to worry about jar deployment, you can translate the example into Javascript (usually just adding the importPackage() method calls and changing the hard typed variable declarations into var declarations). Then you can pragmatically set data set.
But one word of caution, if all these data files don't have the same columns, then you will need to manually add the tables to the report design as well, which is shown in this example here:
http://digiassn.blogspot.com/2007/11/birt-dynamic-adding-tables-and-columns.html
John