Chapter 3. Basics

3. Basics

In the previous chapter we saw that ReportServer functionality is exposed by services. In this chapter we discuss the basics of scripting within ReportServer. This includes passing parameters to scripts, accessing various services, interpreting error messages, working with entities, reading and writing text files and more.

3.1. Executing Scripts

As we have seen, scripts in ReportServer are executed via the Terminal using the exec command. The exec command takes as command a script and passes on any further arguments to the script. You can access command line arguments in your script via the variable args. Suppose we adapt our hello world script as follows:

package myscripts

tout.println('Hello ' + args )

If we now execute the script as

exec helloworld.groovy John

You will get the output

Hello [John]

The square brackets around the name, indicate that the args variable is in fact an array, or rather a groovy collection. If we again change our script to

package myscripts

tout.println('Hello ' + args.reverse() )

and call it with

exec helloworld.groovy John Doe

the output will be

Hello [Doe, John]
3.1.1. Return Values

Scripts have return values. The return value will be output in the terminal. You can either explicitly return from a script via the usual "return x" instruction or else the last line of your script will be interpreted as return value. Thus, we could change our above script to

package myscripts

'Hello ' + args.reverse()

to get the same effect: an output in the terminal.

3.2. Executing Scripts via URL

Besides executing scripts from the terminal, you can execute scripts by calling a specific URL. To execute a script with ID 15 you need to call


The following parameters are available

id The script's id.
path Alternatively to specifying an id you can specify the path of a script. E.g.: http://SERVER:PORT/reportserverbasedir/reportserver/scriptAccess?path=/bin/myscript.groovy
args The arguments to be passed to the script.
exception In case of an exception the server will not respond with an error message. In order to make the server respond with the actual exception set this parameter to true.
commit Whether or not the script should be executed in commit mode.

If executing a script via URL you have access to the predefined variable httpRequest as well as httpResponse which provide access to the HTTP request and response object.