### Using the exit functions

This section provides you with two examples to further understand the exit functions.

#### Example 1: Using parameters in the exit functions

In this example, we provide a simple application which will run at all the three times, BeforeRun, AfterInitParameter, and AfterRun.

1. Develop your Java files to implement the methods. In the example, copy the following code and save it as testa.java to `<install_root>\help`.

       import java.io.*;
       import java.awt.*;
       import java.net.*;
       import jet.util.*;

       public class testa implements JURLExecuter
       {
               public boolean exec(String[] params)
               {
                       System.out.println("testa : ");
                       for (int i = 0; i < params.length; i++)
                       {
                               System.out.print("\"" + params[i] + "\",");
                       }
                       System.out.println();
                       return true;
               }
       }

2. Compile testa.java to generate the class file testa.class in `<install_root>\help`.
3. Add the path `<install_root>\help` to the class path of the file used to start JReport Designer, that is JReport.bat in `<install_root>\bin`.
4. Start JReport Designer with the modified batch file, then open a report with parameter.
5. In the Report Inspector, select the node that represents the report and specify the class and give parameters for the three functions, for example:

   JURL:/ - The standard format, and followed by the class name.
   testa - The class name in this example.
   aa;bb;cc and 123;234;345 - The string type parameters of the class, which are divided by semicolons.
   Param - A pre-defined JReport parameter used in the current report, which is introduced by the symbol @.

   As shown above, two types of exit function parameters are supported, they are:

   - String type parameters, such as aa, C:\ and so on. In this case, the string will be passed directly to the exit function.
   - JReport pre-defined parameters used in the current report, which are introduced by the @ symbol. In this case, the parameter value will be passed to the exit function.
6. Run the report, the report engine will call the class that you specified in the Report Inspector.

#### Example 2: Using formulas in the exit functions

JReport allows you to use formulas in the exit functions. To do this, you can use the Data Container Link function which can return value of any formula to a parameter. And using the parameter in the exit functions, you will get the value of the formula in the exit functions.

1. Create a formula and insert it into a report. It should be put in the child data container.
2. Create a parameter with the same data type of the formula, leaving other options blank, and then insert it into the parent data container.
3. Right-click the parent data container and click Data Container Link on the shortcut menu.
4. In the Data Container Link dialog, click the Return Value tab, add the formula in the Field in Child Data Container to the Return Value box, then click OK.

   Now, you have finished passing value of the formula to a parameter.

5. Use this parameter in the exit functions with the method described in Example 1, and then the final value of formula will be returned in the exit functions.

Notes:

- When a JReport parameter is used as the parameter of the BeforeRun function, no JReport parameter value will be returned, and the returned value will be the JReport parameter name with the @ symbol.
- For the JReport parameter that are used as exit function parameters, they must be used in the report. Otherwise, no value will be returned.
- If you want to publish the report to JReport Enterprise Server and run it there, you should publish both the report and the catalog file to JReport Enterprise Server. However, do not forget to add the path to the class path option in the batch file that starts JReport Enterprise Server.
- Using formulas in exit functions can also be realized by using returning values in subreport. Thus, you need to pass value of a formula in the subreport to a parameter in the main report.