InetSoft Product Instructions: Reusing Scripts in Multiple Reports

You can save commonly-used scripts as functions in the Script Library. This allows you to easily reuse these scripts in multiple report elements and multiple reports. By saving common script tasks to the script library, you can keep your main scrips short, simple, and easy to maintain.

To understand the advantages of the Script Library, consider the script below, which computes the total of a table column:

var total = 0;
 
for(var r = 1; r < table.length; r++) {
  total += table[r][col];
}

This is a common task, which you might need to perform on different table columns, on different tables, and in different reports. Rather than writing the same script again and again for each case, you should reuse the original script. For example, you can save this simple script into the Script Library as a function called “tableTotal()”.

function tableTotal() {
  var total = 0;
 
  for(var r = 1; r < table.length; r++) {
    total += table[r][col];
  }
  return total;
}
visual analysis report example

You can then execute the script by calling the “tableTotal()” function from within any element or report script. The following sections explain how to create and use JavaScript functions and the Script Library.

dashboard demo
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.

Adding a Function to the Script Library

The Script Library is a collection of functions, which can be called from any report with access to the Library. To add a new function to the library, follow the steps below.

  1. Select Edit → Script Library from the Report Designer menu. This opens the 'Script Library' dialog box.
  2. Click the 'New' button. This prompts you to enter the function name.
  3. Enter a name for the new function, and click 'OK'. This opens the Script Editor, and displays a function skeleton with empty parameter list, e.g.,
 function tableTotal() {
 } 

4. Fill in the function body and input parameters (if required).

function tableTotal(col) {
  var total = 0;
 
  for(var r = 1; r < table.length; r++) {
    total += table[r][col];
  }
  return total;
}

Any parameters (e.g., “col”) should be placed in a comma-separated list inside the parentheses that follow the function name. These parameters can then be used inside the function body. 5. Click the 'Save and Close' button to save the script into the library. Note in the above function that the property “table” is not qualified by an element ID (e.g., “Table1.table”). Functions are scoped dynamically (see Function Scopes); therefore, the property “table” refers to whichever Table element called the tableTotal() function. You can therefore call this tableTotal() function from within any table element to operate on that particular table element.

Editing a Function in the Script Library

The Script Library is a collection of functions, which can be called from any report with access to the Library. To edit a function in the library, follow the steps below.

  1. Select Edit → Script Library from the Report Designer menu. This opens the 'Script Library' dialog box.
  2. Click the 'Edit' button. This opens the Script Editor, and displays the function script.
  3. Make the desired edits.
  4. Click the 'Save and Close' button to save the script into the library.

Function Scopes

Function scoping is dynamic. This means that the scope in which the function executes is the scope of the function caller. For example, if a function is called from the scope of a script on the element with ID Table1, then all of the properties of element Table1 are available to the function. Properties that are not qualified with an element ID (e.g., “table,” “visible,” as opposed to “TableX.table,” “TableX.visible”) refer to the caller, Table1.

This scope rule means that if a variable is not declared within a function, the script engine will try to find it in the enclosing scopes. Exactly which object will be located depends on where the function is called. To avoid ambiguity, when you use a variable in a function, you should either declare it in the function, or pass it in as a parameter.

More Articles About Reporting

Assortment of Reporting Services Dashboard Examples - This predictive music industry dashboard report example by InetSoft can be easily embedded into applications to help creators find the next hot music genre in certain areas. In the example dashboard, the most important audio features impacting popularity are identified by regression model. Moreover, end user can deep dive into the music fusion by checking simulated decision tree of genre classification. This sales-by-state sales performance reporting dashboard gives a broad visual breakdown of revenue, prices, and profits, by product line. Color is used in several of the charts to add another dimension. The live version features a mouseover chart, packing in even more information without wasting dashboard real estate...

Department Store Buyers Analytics - Department store buyers rely on predictive analytics to make informed decisions regarding merchandise selection, pricing, inventory management, and marketing strategies. Predictive analytics involves analyzing historical data, current trends, and various influencing factors to forecast future outcomes. Here's how department store buyers typically leverage predictive analytics: Demand Forecasting: Predictive analytics helps buyers anticipate consumer demand for different products. By analyzing past sales data, seasonal trends, demographic information, and economic indicators, buyers can forecast which products will be popular in the upcoming seasons. This allows them to make informed decisions about which items to stock up on and which ones to reduce or eliminate from inventory. Inventory Management: Effective inventory management is crucial for department stores to avoid stockouts and overstock situations. Predictive analytics...

Federal Budget Monitoring Dashboard Example - The Federal Budget Monitoring Dashboard below is an example of one of InetSoft's interactive web-based applications for federal agencies or departments. This particular chart allows users to monitor and research recipients of federal monetary funds by geography or type of award. With a point and click environment, users can drilldown into details by specific query such as state or population for an accurate analysis on one unified screen. With InetSoft's easy-to-use drag and drop design tools, users can quickly build productive analytical tools like this one, that aid day-to-day operations, as well as keep track of and achieve long term goals and objectives. Federal agencies can remain ahead of the game knowing where monetary funds are. InetSoft has a library of charts and visualization types to choose from, including geographic mapping, heat maps, and scatter plots...

More Mobile BI Dashboard Examples - This mobile product return analysis dashboard highlights how a dashboard can incorporate many different pastel shades and not be overwhelming. This allows color to be used as an additional dimension on both dashboard charts. Tapping any of the colored data points with a finger reveals which categories are signified by which colors. This mobile marketing leads dashboard dashboard provides an overall picture of new leads, their sources, and their conversion rates, with a large map chart displaying new leads performance by state. A slider below one of the line charts modifies the change rate that results in a chart highlight...

Shopping Center Management Data Exploration - Global Malls Inc. is a mid-sized company managing a portfolio of 15 shopping centers across North America. These centers serve a diverse range of customers, offering retail stores, dining options, entertainment, and event spaces. Each center operates independently, but the corporate office oversees general management, leasing, and tenant relations. The business model is driven by maximizing tenant occupancy, optimizing foot traffic, and providing an excellent customer experience to attract shoppers and boost sales for tenants. The competitive landscape of the retail sector has become increasingly challenging, with e-commerce rising and shifting consumer preferences. Shopping centers have been compelled to reinvent themselves by focusing on customer engagement, experience, and operational efficiency. Global Malls realized that making decisions purely based on historical data and intuition was no longer effective. They needed better insights into tenant performance, foot traffic...

Wastewater Management Reporting Software - The wastewater management department typically uses a variety of key performance indicators (KPIs) and metrics to monitor and improve the efficiency, effectiveness, and sustainability of their operations. These KPIs and metrics help assess various aspects of wastewater treatment and management processes. Here are some common examples: Effluent Quality Parameters: Chemical Oxygen Demand (COD): Measures the amount of oxygen required to oxidize organic compounds in wastewater, indicating the level of organic pollution. Biological Oxygen Demand (BOD): Indicates the amount of dissolved oxygen needed by aerobic organisms to break down organic material in wastewater, providing insight into the organic pollution level and the health of the aquatic environment. Total Suspended Solids (TSS): Measures the concentration of solid particles suspended in wastewater, which can affect water clarity, aquatic life, and treatment processes...

Previous: More Report Scripting