How To Work On Variable In Action

This recipe demonstrates how to work on variable in action.

Steps taken:

  1. Create a report template (VariableInAction.rml) using the given datasource (FruitSales.ds).
  2. Enter the following script into “Report Properties > Scripts > On Render Begin”:pagecount=0;
    pageCount = 0;
    pageFooters = new java.util.ArrayList();
  3. 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;
    }
  4. Enter the following script into “Functions > Render If”:pagecount++ !=0
  5. Add a Data Field (Type: Script) into the blank area of “Page Header”. Enter the following script into “Field Properties > Field”:"PageCount = " + pagecount
  6. Add a Data Field (Type: Script) into the blank area of “Page Footer”. Enter the following script into “Field Properties > Field”:"PageCount = " + pagecount
  7. 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;
  8. 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)