Calling Functions

In Interactive Reporting, all functions defined in the current script or defined globally or at a higher level than the current script can be called.

Note:

Use caution when working with global variables. Global variables are visible throughout Interactive Reporting, including to computed column calculations and report section expressions.

Defining a function names the function and specifies what happens when the function is called. Calling the function performs the specified actions with the indicated parameters. For example, to call the function square (see Defining Functions) with an argument of 5, you call square(5). The function executes its statements and returns the value 25.

Function arguments can be strings, numbers, and objects. Functions can be recursive; that is, they can call themselves.

Example—Recursive function that computes factorials:

function factoring) {
  if ((n == 0) || (n == 1))
    return 1
  else {
    result = (n * factorial(n-1) )
  return result
  }
}

You can compute the factorials of 1 through 5 as follows:

a=factorial(1) // returns 1
b=factorial(2) // returns 2
c=factorial(3) // returns 6
d=factorial(4) // returns 24
e=factorial(5) // returns 120