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 get list of dataset columns used in a report?
ekta
<p>Hello,</p>
<p> </p>
<p>I have a requirement where I need to know what all columns are being used in a report from a data set when the report is executed.</p>
<p> </p>
<p>For example. I have a DataObject A which has a data set B with 4 columns Customer, Model, Color, Number.</p>
<p> </p>
<p>While designing report a report(report1) only two of the above mentioned columns are being utilized in the report. Similarly there is another report (report2) which uses same dataobject and again uses any 3 of the above mentioned columns.</p>
<p> </p>
<p>Now while executing report I need to know list of columns that are being used in that particular report.</p>
<p> </p>
<p>How can we achieve this? Is there some api present which can give me list of columns added in a report?</p>
<p> </p>
<p>Or do we have any mechanism like reportContext.getReportRunnable().designHandle.getXXX that might help me get a list of columns that are used in the report.</p>
<p> </p>
<p>Thanks</p>
<p>Ekta</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
JFreeman
<p>I am not aware of a call that will return all columns used within the report design.</p>
<p>You can however add scripting to the elements within the report to get the columns used with the specific elements.</p>
<p> </p>
<p>For example, if you have a table, you can build an array of the columns used in the table:</p>
<pre class="_prettyXprint _lang-js">
var numColumn = this.getColumnCount();
var columnNames = [];
for(var i=0; i<numColumn; i++){
columnNames.push(this.getRowData().getColumnName(i));
}
</pre>
Atul Arora
<p>Instead of putting this logic in individual elements like table, chart etc. Is there a way we can put some common code on initialize or beforefactory event method to fetch the details of columns used in all the report elements.</p>
JFreeman
<p>Instead of doing it on each element and using this, you can hook the element in beforeFactory and obtain its column bindings that way.</p>
<p>Using the same example of a table, here is a code sample for beforeFactory:</p>
<pre class="_prettyXprint _lang-js">
var myTable = reportContext.getDesignHandle().getElementByID(9);
var columnArray = myTable.getColumnBindings().getListValue().toArray();
var columnNames = [];
for(var x=0; x<columnArray.length; x++){
columnNames.push(columnArray[x].getName());
}
</pre>
Atul Arora
<p>In a report, can i parse & check elements with which a given data set is associated. So that i need not to hard code the data elements.</p>
JFreeman
<p>You can hook the report body and then iterate through all the elements in the report.</p>
<p>For example:</p>
<pre class="_prettyXprint _lang-js">
var rBody = reportContext.getDesignHandle().getBody();
var rItr = rBody.iterator();
while(rItr.hasNext()){
var rElement = rItr.next();
} </pre>
<p>Then you can perform some logic with each element to get the data set/column information.</p>
ekta
<p>Hello,</p>
<p> </p>
<p>Thanks a Lot!!! for the suggestion and resolution provided. Now I am able to form an array which will have a list of data set columns that are binded with a given report. I am forming this array in beforeFactory()vent of the report.</p>
<p> </p>
<p>I have one more question..</p>
<p> </p>
<p>This array 'columnNames' that is being formed,I want this to be readily available to other events of the reports.</p>
<p> </p>
<p>For example -</p>
<p>1) I have a <strong>data object DO1</strong> which has some scripting done at its end in its open() and fetch() event. It is through these scripts that some data is fetched and populated in a report (whomsoever reports which refers to DO1).</p>
<p> </p>
<p>2) Now I have a <strong>report ReportA</strong> which creates a dataobjecct of its own keeping DO1 as the source and also fetches column list provided by DO1 in its dataset. </p>
<p> </p>
<p>As mentioned above I fetch the column list used in ReportA in the beforeFactory() event of ReportA. Now I want this column list to be available to DO1's open() and fetch() event when the report executes to get the data.</p>
<p> </p>
<p>To achieve this I tried to set columnList as a global variable using -</p>
<p><em>reportContext.setPersistentGlobalVariable("columnNames",columnNames);</em></p>
<p><em>reportContext.setGlobalVariable("columnNames",columnNames);</em></p>
<p> </p>
<p>But these calls didn't help. When I tried to get this global variables in open() event of DO1 it is returned as null.</p>
<p><em>reportContext.getPersistentGlobalVariable("columnNames");</em></p>
<p><em><em>reportContext.getGlobalVariable("columnNames");</em></em></p>
<p> </p>
<p>Interestingly, when I execute same statements in ReportA's open() event then it returns the data correctly. Another thing that I noticed is that DO1's open() is called before ReportA's open(). So, if ReportA open() is giving back results to me correctly then definitely my global variable is not getting lost in between the transition.</p>
<p> </p>
<p>Can you please help me in understanding how a value fetched/computed at Report level can be made available at Data Object's level?</p>
<p> </p>
<p>Is there a way we can set some variable in global space that will be available to Reports as well as Data Objects in BIRT environment? OR is it like dataobjects and reports maintain there own reportContexts and global spaces?</p>
<p> </p>
<p>Thanks</p>
<p>Ekta</p>
JFreeman
<p>beforeFactory should be about the earliest you can get those values in the generation phase and the beforeOpen of the data set's should happen after beforeFactory of the report design.</p>
<p> </p>
<p>Passing the columns names into a persistent global variable should do the trick but you may have to pass them in as a string versus passing the array directly.</p>
<p> </p>
<p>Can you attach your report design so I can take a look?</p>
ekta
<p>Hello,</p>
<p> </p>
<p>I tried persisting column list in a global variable as a string instead of an array, but even that did not help.</p>
<p>It is returning as null.</p>
<p> </p>
<p>-Ekta </p>
ekta
<p>Please find attached rptdesign file and datadesign file.</p>
<p> </p>
<p>I want to persist/ or somehow pass a value from report(UsingSurveyDO.rptdesign) to the extended data object (Survey.datadesign) file.</p>
<p> </p>
<p>'rptColumnNames' is the variable that I am trying to persist.</p>
<p> </p>
<p>Thanks</p>
<p>Ekta</p>
JFreeman
<p>What is it you want to do that would mean you need to pass those values into the .datadesign?</p>
<p> </p>
<p>The persistent global variables are persistent to the reports generation cycle but do not persist any further than that to additional reports of files as they will have their own generation cycle.</p>
ekta
<p>Basically the call to fetch data from my application is being sent through data design file.</p>
<p>While calling data I do not want to fetch complete data (there are over 250 columns ). Fetching complete data will be an overhead and will give me performance issues.<br>
Instead I want to fetch data only for the columns that are used in the report.</p>
<p> </p>
<p>For that I need the list of columns used in the report to be available to the .datadesign file script.</p>
<p> </p>
<p>Now, the list of columns can only be fetched from report (.rptdesign file) but needs to be passed on to data design file to fetch limited data.Is there a mechanism through which this can be achieved?</p>
<p> </p>
<p>Is there any other global context/variable or any other global object that is shared between the lifecycles which can be leveraged to pass on this information?</p>
JFreeman
<p>Is there a reason why you are not building the report against a generated .data files instead of the .datadesign?</p>