How to get ID from LOV? - oracle-apex

I'm learning APEX 5
I have a control named X_CONTROL, where I want to populate his content with an SQL query.
To do that, I need the ID primary key from a table, which should be the ID of the row selected on a Select List control named MY_LIST_CONTROL.
MY_LIST_CONTROL has a list of values taken from a column of the table "MyTable", which is not the ID primary key.
I tried to populate X_CONTROL with this SQL
Select ID from MyTable where ColumnName=:MY_LIST_CONTROL
It doesn't work, and should not work because ColumnName is not "unique", like ID is.
So, the question is, how do I recover, with SQL, the ID of the selected row which correspond to the selected value in MY_LIST_CONTROL.
It should be SQL, because APEX 5 demands an SQL query to populate the X_CONTROL.

I have set up a simple example here on apex.oracle.com:
Whenever a Department is selected (item P32_DEPTNO), its Location is copied into the second item (P32_LOC).
This is done by a dynamic action on P32_DEPTNO defined as follows:
Event: Change
Selection Type: Item(s)
Item(s): P32_DEPTNO
TRUE Action:
Action: Set Value
Set Type: SQL Statement
SQL Statement:
select loc
from dept
where deptno = :P32_DEPTNO
Items to Submit: P32_DEPTNO

Related

Get Select list Item value in IG report column for DML operation

I have a Select list filter on the top of the page. I want its return value to get into any column which I create in IG report automatic DML process.
Suppose, Select list has a value "Step", when I add a row in IG report, that value should be saved into DB for one column which is hidden on UI.
I tried but sometimes it stores the value which I selected in Select list item as my last selection not the current one. Do I need to create Application item for this? Please help. TIA
In this case there is a table ig_tickes with a status column. On the page there is a page item P131_STATUS (select list) with values "OPEN" and "CLOSED". There is an interactive grid on table ig_tickets with column STATUS hidden. Functionality is that user selects a value from the select list and then clicks "Add Row".
Give the interactive grid a static id of "tickets"
Create a dynamic action on change of P131_STATUS with a true action of type "execute javascript code" and code:
var model = apex.region("tickets").call("getViews").grid.model;
model.getOption("fields").STATUS.defaultValue = apex.item( "P131_STATUS" ).getValue();
That's all there is to it.

Get ID from a Row in a Interactive Report

I have an Interactive Report. The Interactive Report is in a form. There are images and other columns, like the ID, in the Report. How can I get the ID of the selected Row and store it in a Page Item?
This is an example based on the "emp" table in the emp/dept dataset. Functionality: when user clicks on an employee name, the empno of that user is set in page item P44_ITEM.
IR source:
select EMPNO,
ENAME,
JOB,
MGR,
HIREDATE,
SAL,
COMM,
DEPTNO
from EMP
There is a page item P44_ITEM that should be set to the EMPNO when the column ename is clicked in the report.
In the report, set the attribute "Column Formatting > HTML Expression" for the column "ENAME" to value <div class="sel-ename" data-empno="#EMPNO#">#ENAME#</div>. Explanation: wrap a div around the text, and add a class "sel-ename" to the cell and a "data-" attribute containing the empno value for the current row.
Create a dynamic action:
Event: Click
Selection Type: jQuery Selector
jQuery Selector: .sel-ename
Create a true action for the dynamic action
Action: Set Value
Set Type: javascript Expression
this.triggeringElement.dataset['empno']
Affected element P44_ITEM
Save and run.

Oracle APEX - set select list selected value based on page item

I have a select list on a page and its source set to a sql query:
SELECT t.name d,t.id r
FROM Table1 t
WHERE t.status = 'New'
AND( t.id = TO_NUMBER(:P3_MY_ID)
OR :P3_MY_ID IS NULL)
ORDER BY 1
And I see mt P3_MY_ID set in session but the value in my select list is not selected. Can anyone help?
The value of P3_MY_ID is getting set in pre-render before regions
List of Values properties group contains the Cascading LOV Parent Item(s) - put P3_MY_ID in there.
Also, make sure that query you wrote actually returns something (using the P3_MY_ID value you use in Apex) when executed in SQL*Plus, SQL Developer, TOAD or whichever tool you use.
to set the value of a select list you need to create a dynamic action set the event to when change>selection type page item> your item P3_MY_ID.
set the true action to set value> set type sql statment> your query> affected element> type item> your select list

Select DISTINCT Query Corrupts result in record set

I've used recordset to populate combobox. When I write normal select query the output comes out to be correct but when I write select query with DISTINCT the combobox is populated with weird strings. Could anyone tell me as to what I'm doing wrong.
allSqlUsername.Format(_T("SELECT PatientName from PatientDetails;"));
recsetname.Open(CRecordset::forwardOnly, allSqlUsername, CRecordset::readOnly);
while (!recsetname.IsEOF())
{
recsetname.GetFieldValue(L"PatientName", patientNameC);
m_autocompletename.AddString(patientNameC);
recsetname.MoveNext();
}
New select query - allSqlUsername.Format(_T("SELECT DISTINCT PatientName from PatientDetails;"));

Oracle Apex - Select list populates text field

I'm using Oracle Apex 4.2. I have a select list and a text field. I'm trying to create a dynamic action that should be simple enough but I'm not sure how to do it. Basically depending on what value the user selects from the list of values in the select list, the text field should then be populated. So for example:
Let's say the select list gives the user the choice to select 'Animal', 'Car', 'Person'. If the user selects 'Animal' then the text field should immediately have the value 'cat'. If the user selects 'Car' then the text field should immediately have the value 'toyota'. If the user selects 'Person# then the text field should immediately have the value 'jim' etc.
How would I make this dynamic action?
Thanks,
Stephen.
Create a New Dynamic Action with the following properties
Main Properties
Event: Change
Selection Type: Item
Item(s): [Select List]
Condition: No Condition
True Action
Action: Execute PL/SQL code
Fire When event Result is: True
PL/SQL Code:
Option 1 - use a lookup table
select LOOKUP_VALUE
into :P1_TEXT
from LOOKUP_TABLE
where original_value = :P1_SELECT_LIST;
Option 2 - Use hardcoded values
CASE upper(:P1_SELECT_LIST)
WHEN 'ANIMAL' THEN :P1_TEXT := 'cat';
WHEN 'CAR' THEN :P1_TEXT := 'toyota';
WHEN 'PERSON' THEN :P1_TEXT := 'jim';
ELSE :P1_TEXT := null;
END CASE;
Page Items to Submit: [P1_SELECT_LIST]
Page Items to Return [P1_TEXT]