# Default Requester with Login User

In the Order Management App, the **Requester field** should be automatically populated with the **currently logged‑in user**.\
This prevents manual input errors and ensures consistency between the request data and the authenticated user.

This section explains how to retrieve the login user from the session and **automatically set the value of the “Requester” field when creating a new order request**.

The solution uses:

* **Java customization** in MasterWeb, and
* **Entity Action configuration** in App Designer.

***

### Objective

By completing this section, you will learn how to:

* Retrieve the logged‑in user from the session
* Automatically populate a screen field during INSERT (CREATE) mode
* Implement default values using App Designer customization
* Improve usability and data correctness for requester users

***

### Step 1: Create Java Customization Class

From the **ONEWEB workspace**, create a new Java class in **MasterWeb** with the following details.

**Class name**

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

**Java code**

```
package com.manual.doc.order.java;

import java.util.HashMap;

import org.apache.log4j.Logger;

import com.master.form.EntityFormHandler;
import com.master.util.EAFManualUtil;
import com.master.util.ProcessAction;
import com.master.util.ProcessHelper;

public class OrderRequestRequesterInsertMode extends ProcessHelper implements ProcessAction {

    Logger logger = Logger.getLogger(OrderRequestRequesterInsertMode.class);

    @Override
    public void modifyInsert() {

        logger.debug("========= Get userName from user login and put to Requester on screen =======");

        // Get entity ID from session
        String entityID = (String) getRequest().getSession().getAttribute("entityID");
        EntityFormHandler entityForm =
        (EntityFormHandler) getRequest().getSession().getAttribute(entityID + "_session");

        // Get main module ID
        String moduleID = entityForm.getMainModuleID();

        // Get login user
        String userName = (String) request.getSession().getAttribute("userName");

        // Get data HashMap of the module
        HashMap hRequester = EAFManualUtil.getDataHashMapFromSession(moduleID, request);

        // Set value of field "REQUESTER" to login user
        hRequester.put("REQUESTER", userName);
    }
}
```

This class is executed during **INSERT (Create)** mode and automatically assigns the logged‑in user to the `REQUESTER` field.

***

### Step 2: Deploy the Java Class

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

After deployment, the class

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

will be available for use in App Designer.

***

### Step 3: Open Entity in App Designer

1. Go to **App Designer**
2. Open entity

   ```
   Doc Order Request - Requester
   ```
3. Click **Edit**

***

### Step 4: Configure Entity Action for INSERT (CREATE)

1. From **Tools > Action**, drag **Entity Action** to the area under the entity name
2. The action appears (typically associated with CREATE / INSERT mode)
3. Click the **pencil icon** to edit the action
4. In the **Action Field Configuration** dialog:
   * Set **Class Action** to:

     ```
     com.manual.doc.order.java.OrderRequestRequesterInsertMode
     ```
5. Click **OK**

> This action is executed automatically when the entity enters INSERT (CREATE) mode.

***

### Step 5: Save the Entity

Click **Save this Entity** to apply the configuration.

***

### Step 6: Test the Configuration

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

   ```
   SETTING > Refresh Cache
   ```

   (to reload updated App Designer configuration)
3. Open menu:

   ```
   DOC Order Request
   ```
4. Click **CREATE**

**Result**:\
The **Requester** field is automatically populated with the currently logged‑in user.

***

### Summary

In this section, you have:

* Implemented Java customization to retrieve the login user
* Automatically populated the Requester field during INSERT mode
* Integrated custom logic with App Designer using Entity Action
* Improved data accuracy and user experience

This customization ensures that every order request is **correctly associated with the authenticated requester**, and demonstrates how **App Designer Customize** can be used to enforce business rules at screen level in the **Order Management App (Web)**.


---

# 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/tutorials-examples/order-management-app-web/app-designer-customize/default-requester-with-login-user.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.
