Oracle Apex: Get Display Value from Select List

In this tutorial, you will learn how to get display value from the Select List in Oracle Apex.

Usually, when we get the value using PL/SQL V() or binding methods (:), then we get the return value from the Select List.

But if you want to get the display value from the Select List, then you have to use the JavaScript API method displayValueFor() with apex.item namespace.

Method displayValueFor() returns the display value of the selected element on behalf of the return value.

Meaning to get the display value from the Select List, you have to pass the return value as an argument to the displayValueFor() method.

Getting Display Value from The Select List in Oracle Apex

For example, we have a Select List item P2_PRODUCT_LIST based on the following query:

Select product_name d, id r 
   from eba_cust_products
order by product_name;

In this case, the Select List P2_PRODUCT_LIST will display the product name and will return the value product id.

First, we will see how to get the returned value from the P2_PRODUCT_LIST using the JavaScript, because this is also needed to get the display value.

Get Return Value from Select List Using JavaScript

apex.item('P2_PRODUCT_LIST').getValue();

The above JavaScript code will get the return value from the Select List P2_PRODUCT_LIST.

You can get this value into a variable or can show directly using the alert message. For example:

var retValue;
retValue = apex.item('P2_PRODUCT_LIST').getValue();
apex.message.alert(retValue);

Get Display Value from Select Using JavaScript

To get the display value of the selected element from P2_PRODUCT_LIST use the following code:

var retValue, displayValue;
retValue = apex.item('P2_PRODUCT_LIST').getValue();
displayValue = apex.item('P2_PRODUCT_LIST').displayValueFor(retValue);
apex.message.alert(displayValue);

Output

Get display value for selected element from select list in Oracle Apex.

Related tutorials:

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

3 Comments

  1. Begin
      for i in (select EMPNO,ENAME,DEPTNO from emp_temp where VALID_DATA_YN = 'Y') 
      loop

        insert into emp(EMPNO,ENAME,DEPTNO)
        values (i.EMPNO,i.ENAME,i.DEPTNO) ;
        --insert into emp(EMPNO,ENAME,DEPTNO) values (9001,'mmp',20);     
        --apex_util.set_session_state('P45_DATA_UPLOAD_VALIDATE_IMPORT','X') ;
        --execute immediate ('TRUNCATE TABLE EMP_TEMP');
      end loop;
      commit;
    end;

    In above, I stored imported data in EMP_TEMP table
    then validated VALID_DATA_YN = 'Y' means validate Data , 'N'  means Invalid data.
    now I going to click om Import Data to insert in EMP table
    BUT NOT INSERTED RECORD INTO EMP TABLE ??

    1) This is done through Dynamic Action -- Plsql Code as above
    2) Processing --> processes --> import data --> plsql code as above

    Thanks

    MAHENDRA

    • Your PL/SQL code looks fine and it should run properly, whether it is written in dynamic action or in a process.

      Also, you should use NVL for such flag fields, for example:

      select EMPNO,ENAME,DEPTNO from emp_temp 
         where nvl(VALID_DATA_YN, 'N') = ‘Y’
      

      if you still not get success, then you have to debug it. And to debug, you can follow the below approach:

      Create a table, for example, debug_code with two columns srlno and description.

      Now before opening the for loop insert a record into it so that you can confirm that control is coming into this section.

      Then insert a record after the insert statement in loop. Also, try to insert cursor column values.

      Then you will be able to find where the exact issue is.

Comments are closed.