In this article
In JScript, to create a function, you start with the function keyword followed by a name. To specify that this is a function and not a normal variable, the name of the function is followed by parentheses.
As a function is a task, its job is described between curly brackets ( "{" and "}") typed after the parentheses of the function.
Example
function Welcome()
{
}
The section between the curly brackets is referred to as the body of the function. In this section, you type what the function is supposed to do:
function Welcome()
{
print ("Welcome to this Reportal Scripting course!!");
}
Note: Public functions cannot be used in a class in Reportal as it will return an error. The static keyword is used.
Also, there are several context-states that must be passed to a code-library script:
| User | user |
| Report | report |
| ConfirmitFacade | confirmit |
| Logger | log |
| Mailer | |
| ReportState | state |
| ScriptPageContext | pageContext |
| ScriptingSettings | settings |
Example
class myCar
{
var Model : String = "Honda"; // public field
function sayHello() // public method
{
return "Hello";
}
}
var c : myCar = new myCar;
print(c.sayHello() + ", I own a " + c.Model);
This will output: "Hello, I own a Honda".
Calling a Function
Using a function is also referred to as calling it. The simplest way to call a function is by writing the word function, followed by the function's name, followed by parentheses, and finally followed by a semi-colon.
Example:
function Welcome()
{
print ("Welcome to this Reportal Scripting course!!");
}
Welcome();