Product How-To: Calculating the Page Total

Calculating the page total itself is very simple. First declare two report-level variables in the onLoad Handler, total1 and total2. These will be used to store the totals over 1000 and below 1000 on the current page.

var total1 = 0; // for total over 1000 
var total2 = 0; // for total under 1000 

Next, add a script to the total field (Text) in the Content band to add the total value to the two total variables, and to display the appropriate highlighting.

// calculate page total and highlight
if(value > 1000) {
   total1 += value;
   band.background = [0,255,0]; // green
}
else {
   total2 += value;
   band.background = [255,255,255]; // white
}

Finally, add an onPageBreak Handler script to display the two totals in the footer, and to reset the total variables.

// assign to footer text element
totalOver.text = formatNumber(total1, "$#,##0.00");
totalBelow.text = formatNumber(total2, "$#,##0.00");

// reset totals
total1 = 0;
total2 = 0;

Band Rewinding

One complication of page-level calculation is the fact that a band can be rewound to a new page during printing. Therefore, if you leave the report as it currently is, the page total may contain an extra value from the next page. To address this, you will add logic to handle the rewinding of a band.

To “undo” the effect of rewinding, you first need to determine what the last band did before it was rewound. In the onPageBreak Handler handler, you can check if the last band was rewound, and undo the last action. For this example, declare a report-level variable in the onLoad Handler to hold the last value added to the total variables.

var lastValue = 0; 

In the script for the total field, simply store the last number added to the total in the variable.

lastValue = value; 

Finally, add code to the onPageBreak script to determine if rewinding occurred, and to undo its effect.

// if rewound, undo the last value total
if(event.rewound) {
   if(lastValue > 1000) {
      total1 -= lastValue;
   }
   else {
      total2 -= lastValue;
   }
}

Since you don't want to lose the last value for the next page, add another block at the end of the onPageBreak to push the lastValue to the next page's totals.

// if rewound, push last value to next page
if(event.rewound) {
   if(lastValue > 1000) {
      total1 = lastValue;
   }
   else {
      total2 = lastValue;
   }
}

What Does InetSoft's Scripting API Permit an Application Developer to Do?

InetSoft's Scripting API offers application developers a powerful toolset to enhance the functionality and customization capabilities of their applications. Here are some key capabilities that the Scripting API permits:

  1. Custom Data Manipulation: Application developers can use the scripting API to manipulate data within their applications. This includes tasks such as data transformation, aggregation, filtering, and calculations. By leveraging scripting, developers can implement complex business logic tailored to specific requirements without modifying the core application code.

  2. Dynamic Report Generation: The scripting API allows developers to dynamically generate reports based on user inputs or real-time data. This enables the creation of dynamic, data-driven reports that can adapt to changing conditions or user preferences. Developers can use scripting to define report layouts, data sources, and formatting rules programmatically.

  3. Integration with External Systems: With the scripting API, developers can integrate their applications with external systems and services. This includes accessing external databases, web services, or APIs to retrieve or update data. By writing custom scripts, developers can implement integration logic to exchange data seamlessly between different systems.

  4. User Interface Customization: The scripting API enables developers to customize the user interface of their applications. This includes modifying existing UI components, adding new functionalities, or implementing custom workflows. Developers can use scripting to enhance user experience and tailor the application interface to meet specific user requirements.

  5. Automation of Tasks: Scripting allows developers to automate repetitive tasks or workflows within their applications. This includes tasks such as data import/export, batch processing, or scheduled operations. By writing scripts to automate these tasks, developers can improve efficiency and reduce manual effort.

  6. Extensibility: The scripting API provides extensibility to the application framework, allowing developers to extend the functionality of the core application. This enables developers to add new features, plugins, or modules to the application without modifying the underlying codebase. By leveraging scripting, developers can build upon the existing functionality and adapt the application to evolving business needs.


Previous: Banded Reports - Rewound Property