REPORTER 22.1
JavaScript

JavaScript

REPORTER has a JavaScript interpreter embedded in it to enable you to perform complex operations through scripts. There are currently 3 ways to run a script in REPORTER.

  • Running a library script installed in the /library/scripts directory.
  • Inserting a script object onto a page. This does not create any direct output itself, but can create output which other objects in the template use.
  • Running a script from the command line with the -script option.

While most people associate JavaScript with web pages and html, it is a full-featured programming language. Additionally, JavaScript is not Java! JavaScript is completely unrelated to Java.

Hopefully, enough people are familiar enough with JavaScript through the internet to be able to use it in REPORTER. JavaScript has all of the functionality you would expect from a programming language, such as:

  • variables (strings, numbers, booleans, objects, arrays)
  • functions
  • control flow statements such as if while do for switch etc.
  • objects
  • arrays
  • regular expressions
  • maths functions (sin cos, log, sqrt etc)

Additionally, REPORTER extends JavaScript by defining several new object classes specifically for REPORTER . A detailed reference on these classes is given in the JavaScript reference manual. Over time this functionality may be extended. If you need to do something which is not possible with the current functionality then contact Oasys Ltd Support.

This chapter is not intended to be an introduction or a tutorial for JavaScript. There are many resources on the web for that. However, a few examples are given to show the sort of things that are possible with scripts. Additionally, there are several good books on JavaScript. Highly recommended is JavaScript, The Definitive Guide by David Flanagan, published by O'Reilly, ISBN: 0-596-00048-0.

REPORTER supports ECMAScript 6 (and newer) features of JavaScript.

Probably the best way to see what sort of things are easily possible in REPORTER using JavaScript is to look at the library scripts which are given out with REPORTER in the /library/scripts directory. For more details of the scripts see Standard library programs.