You can use a script to customize any use report in Infoplus. These are the steps to add a script to a user report.
You can use a Script to customize a User Report in Infoplus, to develop many custom real-world solutions for your business.
Infoplus Support can help with general questions about how scripting works. For help with a specific script or its outputs, you will need to submit a Pro Services request for paid support. Pro Service request form can be found here.
How To Create a Script for Customizing a User Report
- Create a Script record in Infoplus, and choose the option Report in the Script Typefield.
- The Code field in the Script record will be auto-populated with a comment referencing some of the details explained here, as well as a simple example of adding a column to a report. You will need to edit this code to customize the script to meet your unique needs.
- Edit your User Report, expand the Advanced section of the screen, and choose your script from the dropdown menu:
- Run your Report and review the output.
- If necessary, edit your script's code, and re-run the report again until it's functioning as expected.
Code Details
This is the flow that occurs when Infoplus uses a Script to customize a User Report:
- Infoplus fetches all rows matching the Smart Filter assigned to the report and populates all columns to be included in the report.
- The script is executed, with the report's data made available in an object named report.
- Specifically, the rows of the report can be accessed by calling the getOriginalRows method.
- The script is responsible for determining what the rows in the generated report will be. It does this by calling the addRowmethod.
- This point is critical: If you do not call the addRow method, then no rows will be included in your report. To include all original rows, you must iterate / loop over them, and call the addRow method for each of them.
- This allows you to remove rows from the report if you choose to or to add additional rows if needed.
- After the script completes, the rows which were passed through the addRow method are rendered in the requested formats by Infoplus (Excel, PDF).
Object References
Report type scripts have 3 objects available in their context: report, utils, and infoplusApi.
The report object has the following methods:
Method Name | Parameters | Return Value | Notes |
getOriginalRows | void | List of Row objects | Each object in the list represents a row in the report as fetch by Infoplus. This list object has methods size, which returns the number of elements in the list, and get, which takes a 0-based integer index, and returns the Row object corresponding to that index. These Row objects have 2 methods:
|
addRow | Row object | void | Adds the input Row object to the report that will be produced for the user. The Row object must either be one of the objects returned by the getOriginalRows method, or the duplicateRow method. |
duplicateRow | Row object | Row object | Creates a duplicate of the input Row object. This new row can be added to the output of the report by calling the addRow method. |
addColumn | string column name | void | Adds a new column to the report. The column header will be the value passed to this method. To put values in this column in the rows of the report, call the put method on the Row objects, passing this column name. |
removeColumn | string column name | void | Removes a column from the report. |
The utils object has the following methods:
Method Name | Parameters | Return Value | Notes |
log | string log message | void | Adds a line to the script log record built when the script is executed. |
The infoplusApi object is documented here.
A Note about Using Scripts with Pivot Reports
User report scripts run prior to when the "pivoting" happens in a report. This means that the pre-pivoted rows can be touched using a script but the post-pivoted rows cannot. For example, when working with an order based User Report that has "SLA Status" as a row, this row can be used by a script, but once this field is pivoted so "Shipped On Time" and "Shipped Late" become rows in the report with counts, those two rows cannot be accessed by a script.
Example Use Cases
Add Additional Columns
An extra column can easily be added to a report by using the addColumn method plus looping over all rows in the report and putting the desired value into the column. Here's an example script that does this, to add the Cubic volume of Items to a report on the Items table: