Scenario: I have a cascading select list (with multiple selections option enabled) on a page. In addition to the refreshing of the list of values I also want to select certain values by default.
Solution: Use a Dynamic Action Event type of "After Refresh" to perform the actions necessary to set the values.
Demo
In the example the list of employees is refreshed when the department is changed. It is a cascading select list which will list the employees in the department selected.
The desired functionality is, when the employees list is refreshed the page needs to auto-select the employees that have a salary higher than $1500.
A Dynamic Action is created that is executed after the refresh of the employee list.
Name: Set LOV Values
Sequence: 10
Event: After Refresh
Selection Type: Item(s)
Item(s): P94_EMP
The first true action is used to get the list of employees which have a salary greater than $1500 and store the values, separated by colons, in a hidden page item.
Sequence: 5
Action: Set Value
Set Type: SQL Statement
SQL Statement:
SELECT LISTAGG(empno,':') WITHIN GROUP (ORDER BY empno)
FROM emp
WHERE deptno = :P94_DEPT
AND SAL > 1500
Page Items to Submit: P94_DEPT
Selection Type: Item(s)
Item(s): P94_EMP_TEMP
The second true action is used to set the selected employees from the values that were stored in the hidden page item.
Action: Set Value
Set Type: JavaScript Expression
JavaScript Expression:
("#P94_EMP_TEMP").val().split(":")
Pre 4.2.3 - The dynamic action to set the value of an item to multiple values seems to have a bug in it before APEX 4.2.3. If you need to do this in an APEX version before 4.2.3 you will need to change the 2nd true action to Run JavaScript
Action: Execute JavaScript Code
Code:
$("#P94_EMP").val($("#P94_EMP_TEMP").val().split(":"));