Skip to main content

Oracle APEX: How to Dynamically Fetch User-Specific Data

 Oracle Apex

  • Oracle APEX is a low-code development platform that enables developers to build scalable, secure enterprise applications with world-class features that can be deployed anywhere. It allows developers to quickly create and deliver powerful applications that can solve real world problems and provide effective business solutions.

Purpose

In enterprise applications, it is critical that each user sees only the data they are authorized to access.

This article demonstrates how to dynamically fetch data (e.g.,vehicle details) based on the currently logged-in user in Oracle APEX.

Prerequisites

Before following this guide, make sure you have the following in place:

     An existing APEX application with at least one page

    An Interactive Grid or Interactive Report region displaying data (e.g., Vehicle Details)

   Developer access to App Builder for the application 

Overview

  1. Retrieve the employee ID based on the currently logged-in user (:APP_USER)
  2. Store the employee ID in a hidden page item (P398_EMP_ID)
  3. Use the employee ID to fetch the corresponding vehicle ID (P398_VEHICLE_ID)
  4. Filter the report or Interactive Grid using the retrieved vehicle ID

 Implementation Steps

Step 1: Create a Hidden Page Item for Employee ID

Create a hidden item to store Employee ID

Hidden page items are used to store intermediate values during page processing. They are not visible to the user but can be referenced in SQL queries and dynamic actions using bind variable syntax.

In the Page Designer, create a new page item with the following configuration:

  • Name: P398_EMP_ID
  • Type: Hidden
  • Value Protected: No (so that Dynamic Actions can set its value)

 

Step 2: Set the Source of P398_EMP_ID to Fetch the Logged-In User

 Default --- Type: SQL Query

Use the following SQL to get the logged-in user

SELECT m.employee_id 
FROM user_m m
WHERE LOWER(m.user_desc) = LOWER(:APP_USER)

 Key points:

        :APP_USER is a built-in APEX bind variable that contains the authenticated session username.

        The LOWER() function on both sides ensures case-insensitive matching, which is important if usernames are stored in mixed case.

 

Step 3: Create a Dynamic Action Under Page Item P398_EMP_ID

Create a Dynamic Action that triggers when the value of P398_EMP_ID changes

 Create a Dynamic Action with the following settings:

        Name: Employee id

        Event: Change

        Selection Type: Item

        Item: P398_EMP_ID

Action  

Now define the True Action uses a PL/SQL Expression to push the value of P398_EMP_ID into session state so it is available as a bind variable for the SQL query in True Action

        Action: Set Value

       Set Type: PL/SQL Expression

Enter the following as the PL/SQL Expression:

:P398_EMP_ID

Items to Submit: P398_EMP_ID

        Affected Elements

Select Type:  Item(s)

Item(s): P398_EMP_ID

 

Step 4: Create the Vehicle ID Hidden Page Item

Create a second hidden item to store the Vehicle ID that will be resolved in the next step:

  • Item Name: P398_VEHICLE_ID
  • Type : Hidden
  •  Value Protected: No

 

Step 5: Create a Dynamic Action to Fetch the Vehicle ID

Dynamic actions enable developers to define complex client-side behavior declaratively without the need for JavaScript.

Purpose: Fetch vehicle ID for the logged-in employee

Create a Dynamic Action with the following settings:

        Name: Set Vehicle ID

        Event: Page Load

 

Under the Action, configure as follows:

        Action: Set Value

        Set Type: SQL Statement

Use following SQL statement

 SELECT d.vehicle_id

FROM vehicle d

WHERE d.employee_id = :P398_EMP_ID
  AND d.status = 'A'

Explanation:

        d.employee_id = :P398_EMP_ID — Filters vehicles to only those belonging to the logged-in employee.

        d.status = 'A'  ----Restricts results to active vehicles only.

 

       Items to Submit: P398_EMP_ID

       Affected Element

Selection Type : Item(s)

Item(s): P398_VEHICLE_ID


 
Step 6: Create a Region to display Data

With both hidden items populated, you can now use them as bind variables in report. Add the following condition to your region's WHERE clause

Apply the filter in your report or region:

SELECT v.vehicle_id,

       v.make,

       v.model,

       v.registration_number,

       v.assigned_date

  FROM vehicles v

 WHERE v.vehicle_id = :P398_VEHICLE_ID

This filter ensures that the report only ever shows records associated with the vehicle of the currently logged-in user. 


Items to Submit: P398_VEHICLE_IDP398_EMP_ID

After completing all configurations, run and test the page. The following screenshot shows the output:

Conclusion

In this article, we demonstrated a simple and efficient approach to implementing user-specific data filtering in Oracle APEX. By leveraging hidden page items, bind variables, and Dynamic Actions, developers can ensure that each user only accesses data relevant to them. This technique enhances both data security and user experience while remaining easy to implement and maintain.

Comments

Popular posts from this blog

Oracle EBS R12 General Ledger (GL) Module – Practical SQL Queries

Introduction Oracle E-Business Suite (EBS) R12 General Ledger (GL) is the core Financial module in Oracle EBS R12. It is used to manage journal entries, accounting periods, balances, and financial reporting. The GL module integrates with Payables (AP), Receivables (AR), Fixed Assets (FA), Purchasing (PO), and Inventory (INV). The main purpose of a general ledger system is to record financial activity of a company and to produce financial and management reports to help the organization make decisions. Below are real-world SQL queries commonly used.   1) View configured Ledgers      Purpose: Fetch Ledger Configuration Details SELECT       ledger_id,      name  AS   ledger_name ,    short_name ,   currency_code FROM     gl_ledgers ORDER BY     ledger_id ;   2) Ledger Information Query Purpose: Fetch Ledger Configuration Details SELECT     gl.name   ...

Exploring AI in Oracle APEX 26.1

Artificial Intelligence (AI) is transforming the way organizations and developers work. Businesses and professionals are increasingly adopting AI tools to improve productivity, automate processes, and build smarter applications. Oracle APEX introduces a significant evolution in application development by integrating governed Generative AI capabilities directly into the low-code platform. This enables developers to build intelligent, conversational applications while maintaining enterprise-grade security and control. In this article we explore AI capabilities in Oracle APEX 26.1 What is AI Agents AI Agents can be created to reason over user requests and take actions through approved AI Tools. Each tool exposes a specific application capability the agent is allowed to invoke, such as retrieving data, running server-side PL/SQL, or executing client-side JavaScript. APEX manages the execution flow by preparing context, dispatching tool calls, executing tools, handling results, and...

Oracle R12 Inventory Configuration: Key points to Avoid Mistakes

Most Oracle ERP R12 inventory problems are not system failures they are process and configuration failures. The same categories of mistakes surface repeatedly across implementations: Focusing on master data control, disciplined transactions, proper OU setup, and strong internal controls prevents operational and financial discrepancies.   This article walks through the four most critical areas where Oracle R12 inventory implementations go wrong, explains why each mistake is costly, and provides recommendations to prevent them. Each section includes the relevant navigation path and configuration screenshots for hands-on reference   1.       Improper Item Master Configuration in Oracle R12   Oracle E‑Business Suite R12 , the Item Master Configuration serves as the foundation of the Inventory module. Two critical components under this configuration umbrella are: Define Master Item Setup Define Item Status Both setups control how items ...