I'm looking for a way to set a value in Popup Lov item. I'm using Oracle Apex and I'm trying to set value of Popup LOV with dynamic action. I would like to set a year after to have choosen a date from a date picker and refresh the year in a popup LOV item.
On Apex I've create a popup Lov item called P2_YEAR and a date picker called P2_DATE. On P2_date, I've created a dynamic action (Client-side Condition item not null - P2_YEAR) with two true condition.
First condition: Execute a Pl\sql code to extract the year:
declare
year number;
tmp date;
begin
tmp:=:P2_DATE;
SELECT EXTRACT (YEAR FROM tmp) YEAR
into year
FROM DUAL;
:P2_EXTRACT_YEAR := YEAR;
return;
end;
:P2_EXTRACT_YEAR is an item hidden.
and second condition: an Exectute Javascript code
$s('extractyear',$v('P2_EXTRACT_YEAR'));
On P2_Year I added in Advanced - CSS classes the class name extractyear.
What I would obtain is to show the year in the popup item box and if I push on arrow to show only the year previously extract from the date.
This configuration doesn't work.
There are 2 portions to your answer: 1) generate the list of values for P2_YEAR. 2) set the value for P2_YEAR
1) This can be achieved using a cascading LOV on item P2_YEAR. Use source
WITH YEARS (yr) AS
(
SELECT TO_CHAR(TO_DATE(:P2_DATE,'DD-MON-YYYY'),'YYYY') + LEVEL - 2 FROM DUAL
CONNECT BY LEVEL < 3
)
SELECT yr as r, yr as d FROM years
and set parent item P2_DATE.
My item P2_DATE has format mask DD-MON-YYYY
Now if the P2_DATE changes, the options in P2_YEAR will change accordingly.
2) do this using a dynamic action on change of P2_DATE
first action: set value, pl/sql expression, EXTRACT( YEAR FROM TO_DATE(:P2_DATE,'DD-MON-YYYY')) on item P2_EXTRACTYEAR
2nd action: execute javascript code, affected element Item P2_YEAR
apex.item("P2_DATE").setValue(apex.item( "P2_EXTRACTYEAR" ).getValue(),apex.item( "P2_EXTRACTYEAR" ).getValue());
Right-click on the :P2_DATE and select Create Dynamic Action. Set the following properties:
Event: Change
Selection Type: Items(s)
Item: P2_DATE
Client Side Condition
Type: Item is not null
Item(s): P2_DATE
Right-click the dynamic action and select either Create TRUE Action. Set the following properties:
Action: Set Value
Set Type: PL/SQL expression
PL/SQL expression : TO_CHAR(TO_DATE(:P2_DATE,'DD-MON-YYYY'),'YYYY')
Items to Submit: P2_DATE
Affected Elements > Selection Type: Item(s)
Affected Elements > Item(s): P2_YEAR
FALSE Action
Action : Set value
Set Type: PL/SQL expression
PL/SQL expression : :P2_YEAR = ''
Items to Submit: P2_YEAR
Affected Elements > Selection Type: Item(s)
Affected Elements > Item(s): P2_YEAR
Related
I have a scenario where I am stuck not getting how do I proceed with it.
Created a LOV -> which holds below values
A-A
A-B
A-C
A-D
I have set the property of LOV item -> Multiple and Separator given : ,
When I select 1st, 2nd & 4th value it should be automatically displayed in my textbox in comma separated format like following : A-A,A-B,A-D
Any solution is much appreciated !!!
Suppose you have a select list item named P92_LOV and a text field page item named P92_TEXTFIELD.
Create a dynamic action on change of P92_LOV
Add a true action
Identification > Action: Set Value
Settings > Set Type: PL/SQL Function Body
Settings > PL/SQL Function Body:
RETURN :P92_LOV;
Settings > Items to Submit: P92_LOV
Affected Elements > Selection Type: Item(s)
Affected Elements > Items(s): P92_TEXTFIELD
Try it out, whenever you select/unselect a value in the select list, the value in the checkbox will change accordingly.
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.
I have an item to enter email id, and two more items to get the values of first/last name and department of that user which we have given without refresh the page or without enter.
Item 1: ex : a...z#gmail.com (text field)
Item 2 : ex Mechanical (display only)
Item 3 : ex Abinnaya Moorthy (display only)
This should happen when we have given the email id and as soon as the cursor is out from email id the two item values should display.
I have used dynamic action but not getting exact output, please let me know.
On Item 1 make a following dynamic action:
Event: Change (I would recommend 'change', although based on your question, you might also be interested in 'Mouse Leave', although it would trigger DA even when no change in item value occurred, for example when someone just clicked on it and clicked away)
Selection Type: Item
Item: your Item 1
First true action: Execute PL/SQL Code
inserting values into your items Item 2 and Item 3, while using your Item 1 as a condition in WHERE clause
Page Items to Submit: your Item 1
Page Items to Return: your items Item 2 and Item 3
Second true action: Refresh
Selection Type: Item(s)
Item(s): your items Item1 and Item2
Let's say I have 1 field like an email field above. Then I have 50 display only fields that values are coming from (Source) SQL queries that depends on email field. How to refresh this fields without refreshing page, but also without Setting its value manually? I would only like to trigger them to perform their Source SQL query and refresh values on the page.
Setting their values by SetValue action will result in having same queries in Dynamic Action and in Source SQL Query for each field. Also for 50 fields DA would have hundreds of SQL lines and would become not maintainable.
assuming you are working on page 9, and the email field is :P9_EMAIL_ITEM, and the name fields are :P9_FNAME_ITEM and :P9_LNAME_ITEM
The email field is a text field (it doesn't matter what the source is)
The name fields should be display only, and in properties the setting "Based On" should be "Page Item Value", set the source property to type Null.
On the email text field, create a new dynamic action, set the When properties to: Event -> Change, Selection Type -> Item(s), Item(s) -> P9_EMAIL_ITEM
Under the dynamic actions you'll have a "New" event, with a "True" folder, and inside it a new action (probably "Show"). Change its action to "Set Value".
change the setting property so that "Set Type" will be "SQL statement", and write a statement with the following structure:
select FNAME_COLUMN, LNAME_COLUMN
from RELEVANT_TABLE
where EMAIL_COLUMN = :P9_EMAIL_ITEM
Under "Items to submit" select the P9_EMAIL_ITEM.
in the Affected Elements properties set Selection type -> Item(s) and Item(s) -> P9_FNAME_ITEM, P9_LNAME_ITEM
In "Execution Options" select NO for Fire on Initialization
what we did on step 5 is "refreshing" the relevant items, without refreshing the page
I just tested it out and here's what works very well:
On Item 1, create a DA on 'Loose Focus'
Create two true actions for 'Set Value', for both Item 2 and Item 3.
Select Settings > Set Type as SQL Statement.
Write query to fetch item 2 and item 3, base on item 1 (I suggest comparing lower cases of both to make it case in-sensitive.)
Items to Submit -> Item 1
And viola, it's done!
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
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]