# Post Process

Everytime the events are posted to the output, you can perform any post process, if need be, using the `Post Process` script. You can use any standard Java or Groovy code in the post process script.

![](/files/-LyaoJpZXoGflYDylwY6)

### Variables Available

The following are the variables available to the script

| Variable        | Description                                                              | Output Type  |
| --------------- | ------------------------------------------------------------------------ | ------------ |
| flowCode        | Flow code                                                                | All          |
| outputEventType | Table name in the target DB                                              | All          |
| inputEventType  | Table/Object name in the source system                                   | All          |
| inputType       | Input Connector Type e.g. Oracle, MySQL                                  | All          |
| outputType      | Output Connector Type e.g. Oracle, MySQL                                 | All          |
| logger          | Log4j logger for debug purpose                                           | All          |
| db              | An instance of [FlowScript](/advanced-topics/post-process.md#flowscript) | All          |
| count           | Total number of events processed                                         | All          |
| events          | List of events `List<Message>`                                           | All Database |
| errorCount      | Total number of events erred out                                         | All          |
| con             | Output database connection used to post the events                       | All Database |
| producer        | The producer used to post the events                                     | Kafka        |
| key             | S3 file Key used to post the events                                      | Amazon S3    |

### FlowScript (db) <a href="#flowscript" id="flowscript"></a>

{% code title="FlowScrip.java" %}

```java
interface FlowScript {

  /**
   * <p>Call this to get a connection to the output database. Throws exception
   * if the output type is not a database. If you call multiple times,
   * then the same connection will be returned.</p>
   * 
   * @return {@link IOConnection}
   * @throws Exception
   */
  IOConnection getTargetDBConnection() throws Exception;

  /**
   * <p>Call this to get a connection to the input database. Throws exception
   * if the input type is not a database. If you call multiple times,
   * then the same connection will be returned.</p>
   * 
   * @return {@link IOConnection}
   * @throws Exception
   */
  IOConnection getSourceDBConnection() throws Exception;

  /**
   * <p>Call this to get a new connection to the output database, discarding any
   * existing connection. Throws exception if the output type is not a database.
   * If you call multiple times, then the same connection will be returned.</p>
   * 
   * <p>This is useful when you want to make a Redshift call after an 
   * exception as shown below</p>
   * 
   * <pre>
   * Connection con = null;
   * 
   * try {
   * 
   *   con = db.getTargetDBConnection();
   *   
   *   Map<Integer, Object> result = SQL.createCall(con, "my_proc(?, ?)")
   *     .bind(1, "bind value 1")
   *     .registerOutParameter(2, Types.VARCHAR2)
   *     .execute();
   *     
   * } catch (Exception e) {
   * 
   *   con = db.resetAndGetTargetDBConnection();
   *   
   *   SQL.createCall(con, "my_handle_error_proc(?)")
   *     .bind(1, e.getMessage())
   *     .execute();
   *     
   * }
   * </pre>
   * @return {@link IOConnection}
   * @throws Exception
   */
  IOConnection resetAndGetTargetDBConnection() throws Exception;

  /**
   * <p>Call this to get a new connection to the input database, discarding any
   * existing connection. Throws exception if the input type is not a database.
   * If you call multiple times, then the same connection will be returned.</p>
   * 
   * <p>This is useful when you want to make a Redshift call after an 
   * exception as shown below</p>
   * 
   * <pre>
   * Connection con = null;
   * 
   * try {
   * 
   *   con = db.getTargetDBConnection();
   *   
   *   Map<Integer, Object> result = SQL.createCall(con, "my_proc(?, ?)")
   *     .bind(1, "bind value 1")
   *     .registerOutParameter(2, Types.VARCHAR2)
   *     .execute();
   *     
   * } catch (Exception e) {
   * 
   *   con = db.resetAndGetTargetDBConnection();
   *   
   *   SQL.createCall(con, "my_handle_error_proc(?)")
   *     .bind(1, e.getMessage())
   *     .execute();
   *     
   * }
   * </pre>
   * @return {@link IOConnection}
   * @throws Exception
   */
  IOConnection resetAndGetSourceDBConnection() throws Exception;

  /**
   * This is called by FLOW after the script is executed
   */
  void close();

  /**
   * This is called by FLOW after successful execution of the script to commit 
   * both the input and output connections when used.
   * 
   * @throws SQLException
   */
  void commit() throws SQLException;

  /**
   * This is called by FLOW after unsuccessful execution of the script to 
   * rollback both the input and output connections when used.
   * 
   * @throws SQLException
   */
  void rollback() throws Exception;

  /**
   * Same as logger.debug
   * @param msg
   */
  void debug(String msg);

  /**
   * Retrieves the value of a given variable
   *
   * @param variableName
   * @return the variable value
   * @throws Exception
   */
  String env(String variableName) throws Exception;

}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://flow-docs.cloudio.io/advanced-topics/post-process.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
