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)
How to work with config-data/typed-data in a report?
iparker
Hello,
I think about the options how to use data from a system configuration into a birt-report.
A little example: In the database are some typed information (for example for categories or other types), but the denotation of these categories is not in the database but in a system-configuration-file (for example in an array-structure). For example I have a database-table “customer” with the field “customer_type” which types the customers into business customers (represented by the database-value 1) and private customers (represented by the database-value 2).
One possibility is to script the output like this:
customer_type = “”;
if(dataSetRow["customer_type"] == “1”)
{
customer_type = “Business Customer”;
}
if(dataSetRow["customer_type"] == “2”)
{
customer_type = “Private Customer”;
}
customer_type;
Another possibility is to create a javascript-array with the category-value as key and the category-name as value into a report variable like this:
var customer_type = new Array();
customer_type[0] = "Empty";
customer_type[1] = " Business Customer ";
customer_type[2] = " Private Customer ";
customer_type;
To access this I have to output my data like this: vars["my_var"][dataSetRow["customer_type"]]. The advantage is that I can use the same data-structe several times in the report.
But both ways are not very advantageously – especially when I have a lot of typed values in the database. So are there other and better ways to handle such kind of problems?
Thanks for some answers!
Timo
Find more posts tagged with
Comments
mwilliams
Hi Timo,
Could you create a flat file dataSet or scripted dataSet out of the values, like:
custTypeNo,custType
1,Business Customer
2,Private Customer
etc...
Then you could join the two dataSets to get the custType value in your report. If I'm not understanding correctly, let me know.
iparker
Hello Michael,
again thanks for your answer. The flat data-source or scripted-data-source is a great idea. Because I never worked with such kind of data structures - are there some more informations how to work with it available?
Thanks again!
Timo
mwilliams
Timo,<br />
<br />
A flat file would just be a .txt, .csv, etc. file formatted like what I wrote above. Then you'd just enter all the possibilities 1 - n and their string representation and set up a flat file dataSource and dataSet for the values. Finally, you'd join the two dataSets on the numerical column.<br />
<br />
For a scripted dataSet, here is an example posting from the devShare to look at:<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/devshare/designing-birt-reports/544-sample-birt-scripted-data-source-example/#description'>Sample
BIRT Scripted Data Source Example - Designs & Code - BIRT Exchange</a><br />
<br />
Let me know if you have any questions.
iparker
Hello Michael,
Thanks again for your answer. Unfortunately I don’t really understand the “Sample BIRT Scripted Data Source Example”. Where do I have to copy the SimpleClass.java-File? First I thought that this Class-Source is part of the CustomersFavorite-Datasource in the report-file, but I don’t found the class-source in the report.
Is it also possible to have such data-structures directly in the script-part of the report?
Thanks again!
Timo
mwilliams
Timo,
With an external java file, you'd just have to jar the class file and include it as a resource in your report, or create a java project so that the .java file can be compiled before running. If you don't want to use the external class, you can define your data in the open script method of your dataSource too.
Hope this helps.