JavaScript Debugging Hints

Even though the Script Editor makes scripting fast and convenient, the JavaScript language poses its own special challenges. One of the biggest challenges is debugging. Unlike strongly typed languages, JavaScript does not have fixed type for variables, which means that no compile type error checking can be done.

This chapter offers a few tips and hints on how to deal with debugging in JavaScript.

BI solution example
Click this screenshot to view a three-minute demo and get an overview of what InetSoft’s BI dashboard reporting software, Style Intelligence, can do and how easy it is to use.

1. Keep the Script Small

The smaller the code, the easier it is to debug if anything goes wrong. Since scripts are normally used to perform relatively simple calculations, there is little reason to introduce complicated structures or organizations. Use functions and the Script Library to help keep your code concise. (See Script Library.)

2. Associate Script with Elements

Since a script can access any element in a report, in many cases it is possible to write a single large script to perform all tasks. This poses a few problems, however:

• A large script tends to grow and become more complicated over time. This makes debugging the script much more difficult.

• If a single script affects many elements, whenever you rename or delete one of those elements, the script will generate an “object not defined” error. This kind of dependency makes report maintenance difficult, because it is not clear to developers which report elements might be under the influence of a remote script.

• When a script on one element affects the properties of other element, the efficacy of the script depends on the order in which the elements are evaluated. Because the rules for element evaluation (see Script Evaluation) are varied, it can be difficult to predict the final result of the script.

To avoid all of these problems, the script that you place on an element should affect only the properties of that element. For example, if you need a script that modifies the properties of element Text1, then add this script to element Text1. The majority of scripts are element-specific and should therefore each be attached to their associated element.

However, certain scripts need to access multiple elements in order to perform calculations, and it would be difficult to break these up into smaller pieces. In general, if a script works on multiple elements, it should be placed in the onLoad Handler. This eliminates the ambiguity of evaluation order: Since the onLoad handler is called before any element-script is evaluated, all onLoad actions take effect in the current thread.

view gallery
View live interactive examples in InetSoft's dashboard and visualization gallery.

3. Use log() to Output Diagnostic Messages

Log() is a global function that can be called to send a message to the log. In Report Designer, log messages are displayed in the Console window. On the report server, log messages are added to the sree.log file and printed to stderr. Log messages can be used to verify whether a script is invoked or to check the order of script execution.

log("Text changed to: " + text);

4. Protect Reports from Script Errors

Because scripts are executed when the report is generated on the server, a script error can cause report generation to fail. To prevent this from happening, you should wrap failure-prone code inside a “try-catch” block, which allows you to trap errors before they affect report execution. See Appendix JS.10.4, The 'try-catch' Statement, for more information.

More Articles About Java Dashboarding

Better Asana Dashboard Software - Project managers foremost need project progress and coordination information such as dashboards displaying Gantt charts. However, the dashboards must be able to go beyond core project management data to give a holistic view of all factors that can impact on-time, on-budget delivery. Asana is a web and mobile application designed to help teams organize, track, and manage their work. InetSoft's Style Intelligence comes with a custom Asana data connector for incorporating project management data...

Evaluate InetSoft's HANA Business Intelligence Solution - Looking for a good business intelligence solution for your SAP HANA in-memory database? InetSoft's pioneering dashboard reporting application produces great-looking web-based dashboards with an easy-to-use drag-and-drop designer. Data scientists can execute and visually analyze the results of their ML models. Business users get maximum self-service to explore their data. View a demo and try interactive examples...

Option for Report Automation Software - Gathering and analyzing data by hand can become a daunting and ineffective approach in creating reports for your organization. What's more frustrating is doing all the work to get results that doesn't satisfy your needs. Traditional BI methods, although useful, can sometimes feel outdated and slow. In some cases, it can have adverse effects on your organizational goals. At InetSoft, we've transcended those conventional methods with our innovative report automation software...

Software for Analyzing Data - Do you have difficulty accessing all the data you need to in order to analyze what you want? InetSoft is your solution. With InetSoft's data analyzing and visualization software, you can expect fresh new insights that will increase both the internal and external performance of your organization. Data analysis is the process of evaluating data and drawing conclusions. When used properly it can help an organization discover things that they would not have otherwise known. Data analysis is implemented in many different fields, such as construction, healthcare, and education as well as many others...

Who Uses Online Reporting Software? - Online reporting software is used by businesses and organizations to create online reports and dashboards for their input requirements. These tools allow viewing, creating, and editing reports through a web interface such as a web browser. Some examples of online reporting software include InetSoft, Insight Software, and Power BI...

Previous: Reusing Scripts in Multiple Reports
We will help you get started Contact us