This recipe demonstrates how to work on variable in action.
Steps taken:
- Create a report template (VariableInAction.rml) using the given datasource (FruitSales.ds).
- Enter the following script into “Report Properties > Scripts > On Render Begin”:pagecount=0;
pageCount = 0;
pageFooters = new java.util.ArrayList(); - Enter the following script into “Report Properties > Scripts > On Render End”:i = 1;
it = pageFooters.iterator();
while (it.hasNext())
{
fn = it.next();
fn(fn.target,i,pageCount);
++i;
} - Enter the following script into “Functions > Render If”:pagecount++ !=0
- Add a Data Field (Type: Script) into the blank area of “Page Header”. Enter the following script into “Field Properties > Field”:"PageCount = " + pagecount
- Add a Data Field (Type: Script) into the blank area of “Page Footer”. Enter the following script into “Field Properties > Field”:"PageCount = " + pagecount
- Define the following function in “Functions > On Render End”:function fn(t,pageNo,pageTotal)
{
t.setText("Page “+pageNo+” of "+pageTotal);
}
fn.target = result.getLogicalElement(0);
pageFooters.add(fn);
++pageCount; - Enter the following script in “Functions > Render If”:pagecount != pageCount;
To download the necessary files for this recipe, refer to the attached ZIP package.
VariableInAction.zip (4.2 KB)