# Validate at Least One Order Item When Submit

In the Order Management App, an order request **must contain at least one Order Item** before it can be submitted.\
To enforce this business rule, **validation logic** needs to be added so that the system prevents submission when no order item exists.

This section explains how to implement **one‑to‑many validation** by extending the existing Java customization and validating data **before the submit action completes**.

***

### Objective

By completing this section, you will learn how to:

* Validate one‑to‑many data relationships during submit
* Access child module data from Java customization
* Prevent form submission when validation fails
* Display user‑friendly error messages on the screen

***

### Step 1: Update Java Customization Class

Open the existing Java class:

```
com.manual.doc.order.java.OrderRequestRequesterInsertMode
```

Override the `validateResult()` method with the following implementation.

#### Java Validation Logic

```
@Override
public boolean validateResult() {

    logger.debug("========= Validate require at least 1 order request item ========");

    boolean result = true;
    String nextEntity = (String) request.getParameter("nextEntity");
    logger.debug("##### nextEntity ##### " + nextEntity);

        // Validate only when submitting the current entity
        if (nextEntity == null || "".equals(nextEntity)) {

        String entityID = (String) getRequest().getSession().getAttribute("entityID");
        EntityFormHandler formEntity =
        (EntityFormHandler) request.getSession().getAttribute(entityID + "_session");

        Vector vError = formEntity.getFormErrors();

        // Get Order Request Item module session
        MasterFormHandler formMaster =
        (MasterFormHandler) request.getSession().getAttribute("MD11784591_session");

        Vector vFormMaster = formMaster.getStoreActionList();
        logger.debug("##### vFormMaster ##### " + vFormMaster);

        // Validate at least one order item exists
        if (vFormMaster.size() == 0) {
        vError.add("Please add order item at least 1 item");
        result = false;
        }
    }
    return result;
}
```

This method checks whether the **Order Request Item module contains at least one record** before allowing submission.

***

### Step 2: Update Module Session ID

In the code above, replace:

```
MD11784591_session
```

with the **actual module ID** of module **“Order Request Item”** in entity\
\&#xNAN;**“Doc Order Request – Requester”**, followed by `_session`.

#### How to Find the Module ID

1. Open entity **Doc Order Request – Requester** in App Designer
2. Click **Edit** on module **Order Request Item**
3. Find the value of **Module ID**
4. Use that value in Java code as:

```
<ModuleID>_session
```

This ensures the validation checks the correct child module.

***

### Step 3: Deploy Updated Java Class

1. From the **ONEWEB workspace**, export `EafMasterEar.ear`
2. Deploy the updated EAR file to the server

The updated class

```
com.manual.doc.order.java.OrderRequestRequesterInsertMode
```

will now include the new validation logic.

***

### Step 4: Test the Validation

1. Log in to **FrontWeb** as a Requester user
2. Click menu:

   ```
   SETTING > Refresh Cache
   ```

   to reload the updated configuration
3. Open menu:

   ```
   DOC Order Request
   ```
4. Click **CREATE**
5. Try to **SUBMIT** the request **without adding any Order Item**

#### Expected Result

* The system prevents submission
* An error message is displayed:

  ```
  Please add order item at least 1 item
  ```

This confirms that validation is working correctly.

***

### Summary

In this section, you have:

* Implemented validation for one‑to‑many relationships
* Ensured at least one Order Item exists before submission
* Used Java customization to access child module data
* Prevented invalid business transactions from being processed

This validation strengthens **data integrity and business rule enforcement** in the **Order Management App (Web)** and demonstrates the power of **App Designer Customization combined with Java logic**.


---

# 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/tutorials-examples/order-management-app-web/app-designer-customize/validate-at-least-one-order-item-when-submit.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.
