Home
Analytics
dynamic text in page header
David1000
<p>Hi,</p>
<p>I am new to BIRT as well as posting on this forum. I have been searching to figure out my question and although I am finding some answers I am still having trouble solving my problem.</p>
<p> </p>
<p>I am working with BIRT 4.6. My report consists of a list with some subreports that are also lists. The whole report is many pages long. The main list has a few groups. What I am trying to do is place in the page header a text field that will reflect the first row of a particular field in my list for each page.</p>
<p> </p>
<p>From what I have read I need to create and use a page variable for this. So in the data explorer tab under variables I created a new page variable. Then In the Master Page Header I placed a grid and inside the grid I placed an auto text variable using the variable I created in the data explorer tab.</p>
<p> </p>
<p>I realize that now I need to get and set this variable with script but I can't figure out the correct syntax to use and where exactly I place this script. I have been trying to understand how to work with variables but I can't quite understand how to make them work. Also the place where the data in my report that I want to be reflected in the page header occurs is in one of my subreport lists.</p>
<p> </p>
<p>So, can anyone help me figure this out or at least point me to where I can learn how to use a page variable in this way.</p>
<p> </p>
<p>Thanks,</p>
<p>David</p>
Find more posts tagged with
Comments
David1000
<p>Perhaps there is a different way to get to solve my query without using variables.</p>
<p> </p>
<p>I added a dynamic text field set to the field I am interested in into the grid of the page header. Now I get one value from the field but it is the value of the first row. This same value repeats every page. So if there was some way to have this value be refreshed every new page perhaps it would reflect the value of the first row of each page? Is it possible to do this?</p>
<p> </p>
<p>Thanks,</p>
<p>David</p>
David1000
<p>OK I finally got it figured out. Besides the needed code, correct syntax, and placement there were other issue that I needed to figure out. I will put it all here for anyone else in need.</p>
<p> </p>
<p>In BIRT report designer 4.6.0</p>
<p>First create a new page variable. Under Data Explorer>Variables right click and select New Variable. Select the Page Variable radio button and create a Name in the Name field. Default value can be left alone.</p>
<p> </p>
<p>In Layout tab click outside of report. Then click the Script tab. In the Script box choose onPageStart. Put the following piece of code in the space below the script box</p>
<p> </p>
<p>reportContext.setPageVariable("your variable name", null);</p>
<p> </p>
<p>Replace your variable name with what ever name you gave to the New Variable you created earlier.</p>
<p> </p>
<p>Now in your report find the field you want to have in the header. I didn't have it in my report because I had concatenated a number of fields into one. So I simply added the field to the report that I wanted in the header. A few cautions here. Don't add a text or dynamic item to your report and then assign it the field you want. This was one of my original problems. The field appears to need to be inserted as a data field. This is easily done by dragging the field from the right data set into the report. Make sure that what ever part of the report this field gets inserted into that it can be accepted. It will only be accepted if that part of the report has a binding that matches that data set and then field. Since I didn't need this field to be displayed in my report (I just needed it in my report so I could use it for the header) I clicked on the field and then in the property editor tab>Properties tab>general>select no display in the display box.</p>
<p> </p>
<p>Now click on the field in the report while you are on the layout tab and then click on the script tab. Choose onPageBreak in the script box and place the following piece of code in the box below the script box</p>
<p> </p>
<p>var your field of interest = this.getValue( );<br>
var first = reportContext.getPageVariable("your variable name");<br>
if (first == null)<br>
reportContext.setPageVariable("your variable name", value);</p>
<p> </p>
<p> </p>
<p>Replace your variable name with what ever name you gave to the New Variable you created earlier.</p>
<p>Replace your field of interest with the name of the field you are trying to get into the page header.</p>
<p> </p>
<p>Now click on the master page tab and drag into the header an autotext Variable item. Once that Item is in the header a dialogue box will appear with a drop down menu. From that drop down menu choose the Variable you created earlier.</p>
<p> </p>
<p>Now when it comes time to print your report first view your report in the web viewer. Then from there if you want a pdf click on the export report button and then pdf as export format. Also in the Fit To area click on the actual size radio button. What I found is that if I viewed my report as a pdf right from the beginning the variables I put in my header did not show. Also I found that when I created a pdf from the web viewer and left the Fit To as Auto that my report had unexplained page breaks in odd places and this caused havoc with the variables I placed in my header.</p>
<p> </p>
<p>I hope this is all helpful for anyone going forward especially if you are not someone who does scripting much or at all as is the case with me. </p>