# Filter Requester Search Screen by Login User

In many real‑world applications, users should only be able to view **their own data**.\
In the Order Management App, Requester users must see **only the order requests that they created**, not those created by other users.

This section explains how to **retrieve the logged‑in user** and **filter search results automatically** so that the Requester search screen displays only records associated with the current user.

This is achieved by combining:

* **Java customization** on the server side, 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
* Dynamically modify the SQL Work Queue used in a search screen
* Register a custom Java class as an Entity Action
* Apply user‑based filtering without changing the core entity SQL

***

### 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.OrderRequestRequesterSearchMode
```

**Java Code**

```
import java.util.HashMap;

import org.apache.log4j.Logger;

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

public class OrderRequestRequesterSearchMode extends ProcessHelper implements ProcessAction {
    Logger logger = Logger.getLogger(OrderRequestRequesterInsertMode.class);

    @Override
    public HashMap getSearchResult() {

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

        // Get main module
        String moduleID = entityForm.getMainModuleID();
        MasterFormHandler moduleForm =
        (MasterFormHandler) request.getSession().getAttribute(moduleID + "_session");

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

        // Append condition to filter by requester
        StringBuilder appendSql = new StringBuilder(" and wf_service_request.requester ='");
        appendSql.append(userName).append("' ");

        String sql = moduleForm.getModuleM().getSqlWorkQueue();
        logger.info("@@@@@ old sql :" + sql);

        StringBuilder newSql = new StringBuilder(sql);
        newSql.append(appendSql);

        logger.info("@@@@@ new sql :" + newSql.toString());

        return EAFManualUtil.loadTableData(request, newSql.toString(), moduleForm.getPage(), moduleForm.getVolumePerPage()
        );
    }
}
```

This class dynamically modifies the search SQL to filter records by the logged‑in user.

***

### 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.OrderRequestRequesterSearchMode
```

will become available for use in App Designer.

***

### Step 3: Configure Entity Action in App Designer

1. Open **App Designer**
2. Search for entity

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

***

### Step 4: Link Java Class to SEARCH Action

1. From **Tools > Action**, drag **Entity Action** to the area under the entity name
2. The action name **SEARCH** appears
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.OrderRequestRequesterSearchMode
     ```
5. Click **OK**

***

### Step 5: Save 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
   ```

   (This ensures the updated App Designer configuration is loaded)
3. Open menu:

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

**Result**:\
Only order requests created by the currently logged‑in Requester are displayed.

***

### Summary

In this section, you have:

* Implemented custom Java logic to retrieve the logged‑in user
* Dynamically modified the SQL Work Queue at runtime
* Integrated Java customization with App Designer Entity Action
* Restricted search results to user‑specific data

This approach enhances **data security, usability, and correctness**, and demonstrates how **App Designer Customization** can be used to handle complex, real‑world business requirements 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/filter-requester-search-screen-by-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.
