# Add Custom SQL

ONEWEB supports the use of **custom SQL** to retrieve or manipulate data when default query behavior does not meet specific business requirements.

Custom SQL can be added to an entity in **two supported ways**:

1. **Module Configuration SQL**
2. **Java Manual Class**

Each approach is designed for different use cases and levels of complexity.

***

### Module Configuration (Inline SQL)

ONEWEB allows developers to define **manual SQL queries directly within the Module Configuration**.\
This method is primarily used to customize how data is retrieved and displayed within Smart Forms and Search screens.

When you open the **Module Configuration** panel for a module, THREE SQL options are available. You can choose the option that best matches your requirement.

***

#### SQL Options in Module Configuration

**SQL ShowList**

* Used to query data displayed in a **1‑Many module**
* Applies to **Insert** and **Update** modes
* Controls how child records are listed inside the form

**SQL Select Row**

* Used to query data for a **1‑1 module**
* Applies to **Insert** and **Update** modes
* Controls how single‑record data is retrieved and shown in the form

**SQL Work Queue**

* Used in **Search Mode**
* Controls which data appears in **Search Results**
* Commonly used for work‑queue or task list customization

***

#### Module Configuration SQL Options

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F0392l05kNBvi5hch4PY8%2F0?alt=media" alt=""><figcaption></figcaption></figure>

***

#### When to Use Module Configuration SQL

Use this approach when:

* You need simple or moderately complex SQL queries
* Data retrieval logic is closely tied to a specific module
* You want quick customization without additional Java development
* Queries are read‑focused and form‑specific

***

### Java Manual Class (Advanced SQL)

For more advanced scenarios, ONEWEB supports executing **custom SQL inside Java Manual Classes**.

A Java Manual Class can be invoked in two ways:

* Through **Java Class Actions**
* Via **AJAX calls triggered by JavaScript**

Within these Java classes, developers can write **custom SQL logic**, just as in a standard Java application.

***

#### Capabilities of Java Manual Class SQL

Using Java Manual Classes allows:

* Complex SQL logic and joins
* Conditional and dynamic query construction
* Integration with multiple data sources
* Transaction and error handling
* Reusable and centralized business logic

This approach is recommended when SQL complexity goes beyond what Module Configuration can reasonably support.

***

#### When to Use Java Manual Class SQL

Use this approach when:

* SQL logic is complex or reusable across modules
* Calculations or business rules are tightly coupled with queries
* Data must be processed before being returned to the UI
* Server‑side control and security are required

***

### Choosing the Right Approach

| Approach                 | Best For                                      |
| ------------------------ | --------------------------------------------- |
| Module Configuration SQL | Simple, form‑specific queries                 |
| Java Manual Class        | Complex, reusable, enterprise‑grade SQL logic |

In many applications, both approaches can coexist—using **Module Configuration** for straightforward queries and **Java Manual Classes** for advanced processing.

***

### Summary

ONEWEB provides flexible and powerful mechanisms for integrating **custom SQL logic** into Smart Forms.

Key benefits include:

* Multiple methods to suit different complexity levels
* Direct SQL customization within module configuration
* Full Java‑based control for advanced SQL logic
* Seamless integration with entities and form behavior
* Support for enterprise‑grade data access patterns

This flexibility allows developers to tailor data retrieval precisely while maintaining performance, scalability, and maintainability.


---

# 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://docs.onewebstack.com/oneweb-platform-th/building-apps/ui-page-designer/ux-ui-customization/smart-form-customization/add-custom-sql.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.
