Example: Attaching and Testing an Event Handler

Examples are available for Java event handlers (below) and .NET.

Java

The example below attaches and tests a sample event handler for reformatting currency amounts in recordset fields. Before you begin, you should review the basic steps for creating an event handler.

This example uses two Java files:

 

Follow these steps to implement the currency formatting event handler:

  1. Start the Design Tool and open the CCSDemo model. Example models are located at Program Files\Micro Focus\Verastream\HostIntegrator\models\CCSDemo.
  2. When prompted to save the model, click Yes and either accept the default location or choose another location.
  3. Click Connect on the toolbar.
  4. Create a folder named fieldformatting under <Documents>\Micro Focus\Verastream\HostIntegrator\models\CCSDemo\scripts\src\ and copy CurrencyFormatter.java and CurrencyFieldHandler.java to the folder.
  5. In the Design Tool, from the Settings menu, click Event Handlers. On the Technology tab, verify that Java is selected, and then click OK.
  6. On the Events menu in the Design Tool, click Rebuild. The Build Output window indicates when the build is complete.
  7. In the Entity window, select the AcctTransactions entity.
  8. Click the Recordset tab, and then click the Fields subtab.
  9. Select the Amount Field, then click the Advanced Properties button.
  10. In the Advanced Recordset Field Properties dialog box, select fieldformatting.CurrencyFieldHandler from the Event Handler list. This dialog box also has options for reviewing the properties of the event handler or inspecting the code in your default Java editor.
  11. Click Close to attach the event handler to the Amount Field. When you return to the Fields tab, the Amount field now has a lightning bolt displayed to the left, indicating that an event handler has been attached.
  12. Click Apply to activate your changes.
  13. To test the event handler, select Recordset Test from the Debug menu. Confirm that AcctTransData is listed as the Recordset and Fetch Records is listed as the Action.
  14. Click Execute. After the test is complete, the returned values in the Amount column have a dollar sign and negative amounts are surrounded by parentheses, as they will be when returned to a client application.

.NET

This example uses two C# files:

Follow these steps to implement the currency formatting event handler:

  1. Start the Design Tool and open the CCSDemo model. Example models are located at Program Files\Micro Focus\Verastream\HostIntegrator\models\CCSDemo.
  2. When prompted to save the model, click Yes and either accept the default location or choose another location.
  3. Click Connect on the toolbar.
  4. Create a folder named fieldformatting under <Documents>\Micro Focus\Verastream\HostIntegrator\models\CCSDemo\scripts\src\ and copy CurrencyFormatter.cs and fieldformatting.CurrencyFieldHandler.cs to the folder.
  5. In the Design Tool, from the Settings menu, click Event Handlers. On the Technology tab, verify that .NET is selected, and then click OK.
  6. On the Events menu in the Design Tool, click Rebuild. The Build Output window indicates when the build is complete.
  7. In the Entity window, select the AcctTransactions entity.
  8. Click the Recordset tab, and then click the Fields subtab.
  9. Select the Amount Field, then click the Advanced Properties button.
  10. In the Advanced Recordset Field Properties dialog box, from the Event Handler drop down list, select fieldformatting.CurrencyFieldHandler. This dialog box also has options for reviewing the properties of the event handler or inspecting the code in your default C# editor.
  11. Click Close to attach the event handler to the Amount Field. When you return to the Fields tab, the Amount field now has a lightning bolt displayed to the left, indicating that an event handler has been attached.
  12. Click Apply to activate your changes.
  13. To test the event handler, select Recordset Test from the Debug menu. Confirm that AcctTransData is listed as the Recordset and Fetch Records is listed as the Action.
  14. Click Execute. After the test is complete, the returned values in the Amount column have a dollar sign and negative amounts are surrounded by parentheses, as they will be when returned to a client application.
Related Topics
Bullet Debugging event handlers
Bullet Event handler guidelines