I have page with Classic Report on it (type = PL/SQL Dynamic Content). What I need it's passing one column value to PL/SQL via Dynamic Action when click on another column. It's no problem to initiate click action, but I don't know how to pass equivalent of #col_name# (not :Pxxx_item_name) to PL/SQL.
Application Express 5.0.4.00.12
I'm not sure what you're trying to pass, so I'm just going to call it "item".
In your report add a custom data attribute to the column, data-item="#COL_NAME#". This would go on the image that's getting clicked. You might need to use the HTML Expression option to set this.
Create a hidden item, P1_ITEM and set Value Protected to No.
Create a Dynamic Action that fires when you click the image in the column.
Create a True action on that DA, Action = Set Value, Set Type = Javascript Expression, the JS expression is this.triggeringElement.dataset[ "item" ], Affected Element > Selection Type = Item, Item = P1_ITEM.
Create another True action on that same DA, Action = Execute PL/SQL Code, Items to Submit = P1_ITEM, and whatever code you want in the PL/SQL code section. You can reference P1_ITEM in your code with :P1_ITEM or V('P1_ITEM').
When the DA fires, it will populate the column value into P1_ITEM, then submit that to the server where it's stored in session state, then run your PL/SQL code.
Related
The same question once again but with (I hope) better explanation:
I created the most simple case:
An Interactive Grid IG with data source EMP ( table with 14 records contains Ename, Job, HireDate, Salary etc. etc.)
Text field P7_ENAME
After running it looks like below:
What I would like to do is to copy Ename from selected record of IG to P7_ENAME field .
I found several tutorials (text and video) how to do it. Most of them suggest to create dynamic action SelectionChange on IG and when TRUE add a JavaScript code something like below:
var v_ename;
model = this.data.model;
v_ename = model.getValue( this.data.selectedRecords[0], "Ename");
apex.item( "P7_ENAME" ).setValue (v_ename);
and the second step is to create another action: Refresh.
So finally I have a dynamic action with two steps : the first one is a Java script code and the second refresh function on my P7_ENAME field.
Sounds simple and it is simple to repeat/implement. A guy (I suppose) from India published a video on YouTube (https://www.youtube.com/watch?v=XuFz885Yndw) which I followed and in his case it works good. In my case it simple does not work - field P7ENAME is always empty, no errors appears. Any idea why ? Any hints, suggestion ?
thanks for any help
K.
The best way to debug and achieve what you are trying to do is as follows:
create the Dynamic action with the following setup:
-when -> selection change[interactive grid],
-selection type -> region, region -> your IG region,
-client side condition -> javascript expression: ```this.data.selectedRecords[0] != undefined```
First action of the true of the DA with the type: execute javascript code and fire on initialization is turned on, code: console.log(this.data.selectedRecords);
Run your page, and check the browser console. You should see an array of columns when you select a record from that IG as follows:
Find in that array, which sort number of the array contains the data that you want to use for the page item. Let's say I want the 3rd element which is "2694" then I should change my dynamic action's execute javascript code to:
var value = this.data.selectedRecords[0][2];
apex.item( "P7_ENAME" ).setValue (value);
The last thing I should do is add another true action (and the refresh action at the end) to the same dynamic action with type 'SET VALUE' and 'PLSQL EXPRESSION' as type, put :P7_ENAME in the expression, items to submit P7_ENAME and affected element: item / P7_ENAME as follows:
I have two region one form and one interactive grid like a master detail(company and company contact person ) how i can make the interactive grid mandatory ,the user can't submit page ,he/she need add at least one row in interactive grid ,
I can do that or I need to change the interactive grid to collection and count the row in validation
This one is a little tricky because of the way processes and validations work with Interactive Grids (they are executed once per submitted row). To work around this, I'll use a page item and a validation that works with it.
The basic idea of this solution is based on the fact that a new row will not have a primary key value. Here are the steps to reproduce (my example was on page 14, update the following as needed).
Create an Interactive Grid (IG) region. The primary key column should be Query Only (which ensures it's null for new rows).
Create a Hidden page item named P14_NULL_FOUND. Set Type under Server-side Condition to Never so that it never renders on the page.
Create an After Submit (before Validations) process. This process will NOT be associated with the IG so it will only fire once. Set the PL/SQL Code attribute to:
:P14_NULL_FOUND := 'NO';
That will clear out the value of the page item prior to the next process.
Create another After Submit process that runs just after the previous one. Set Editable Region to the IG. Then set the PL/SQL Code to something like the following:
if :PK_COLUMN_IN_IG is null
then
:P14_NULL_FOUND := 'YES';
end if;
You'll need to replace ":PK_COLUMN_IN_IG" with the name of the primary key column in the IG, such as ":EMPNO". This process will be run once for each submitted row in the IG. If a null value is found for the primary key column, then that would mean the user added a new row and the value of P14_NULL_FOUND would be set to 'YES'.
Create a new validation. This validation will NOT be associated with the IG so it will only fire once. Set Type to PL/SQL Expression. Set PL/SQL Expression to:
:P14_NULL_FOUND != 'NO'
Then set Error Message to something relevant.
At this point, you should be able to run the page and verify that the processes and validation are working correctly.
There is an another solution;
Create a page item like PX_ROWCOUNT which will hold the data of the row count of your IG.
Assign a static ID to your IG region.
Write a JS function to count the rows of the grid then set it to the page item. Sample function;
function f_setRowCount(){
var grid = apex.region("staticIDOfYourIG").widget().interactiveGrid("getViews", "grid");
var model = grid.model;
var rowCount = 0;
model.forEach(function (record) {
rowCount ++;
});
$s("PX_ROWCOUNT",rowCount);
}
To submit your page and run this function, change your submit button's behavior to Defined by Dynamic Action. Execute your function when user clicks to that button then submit your page via DA.
Add validation to Processing section of the page and check your page item there; PLSQL Expression => :PX_ROWCOUNT > 0
The solution by Hamit works nicely, except of the case of deletion of a row.
My suggestion is to amend the above code by adding inside the loop an if statement to check whether the row is editable or no.
So the code will be
var grid = apex.region("staticIDOfYourIG").widget().interactiveGrid("getViews", "grid");
var model = grid.model;
var rowCount = 0;
model.forEach(function (record) {
if (model.allowEdit(record)) {
rowCount ++;
}
});
$s("PX_ROWCOUNT",rowCount);
I've started to learn APEX just recently.
I've a select list, called LB_TEST1, from which value I want to display in a display only field TB_TEST4
I've set up (inspired by this question):
LB_TEST1
select list (populated from a query)
action when value changed: None (default)
TB_TEST4
based on: page item value
also created a dynamic action:
when: LB1_TEST changes, no condition
action: set value
fire when result is true
set type: static assignment
value: &LB_TEST1
affected elements: TB_TEST4
(fields not listed mainly contain default values)
What happens:
each time I run application at first change of LB1_TEST's value TB_TEST4 is filled by the OLD(!) value of LB1_TEST.
subsequent changes of LB1_TEST are not triggering change of TB_TEST4
How can I fix this?
Modify your dynamic action as below,
Change set type from Static Assignment to JavaScript Expression
Change JavaScript Expression value from &LB_TEST1 to $v('LB1_TEST')
Also, look at how session state works in Oracle APEX. The link in the question you have referred above is a good start --> Doc Link
Demo Page Link --> https://apex.oracle.com/pls/apex/f?p=114083:1
I have an item P0_ITEM, I want to use a value from a particular cell in an interactive report and assign it to the item P0_ITEM, How can this be done?
Set static region ID to something like p1_ir
Define a dynamic action on click of jQuery selector
#p1_ir td
Event scope: dynamic
Execute JavaScript code
$s('P0_ITEM', $(this.triggeringElement).text());
I have problem with multi-select LOVs in Apex 5.
I want to do, in programmatic way, select values in multi-select LOV.
For example I press button and some value will be selected in LOV.
Any ideas how to do this?
If you mean a Select List item that is set to allow multiple values then your button could execute this Javascript:
$('#P123_MY_MULTI_SELECT option[value="AAA"]').attr('selected',true);
$('#P123_MY_MULTI_SELECT option[value="BBB"]').attr('selected',true);
... etc.
Alternatively, you could use a dynamic action, but it wouldn't be any simpler. It would define the affected elements using a jQuery selector:
#P123_MY_MULTI_SELECT option[value="AAA"],#P123_MY_MULTI_SELECT option[value="BBB"]
... and the action would be to execute Javascript code:
$(this.affectedElements)..attr('selected',true);
I'll describe the easiest example:
Create APEX item eg. P1_MULTIPLE
Type = Select list
Allow Multi Selection = Yes
List of Values > Type = Static Values
List of Values > Static values = STATIC:Display1;Return1,Display2;Return2
Create button eg. SET_VALUES
Create dynamic action
Event = Click
Selection type = Button
Button = SET_VALUES
Create true action within DA from step 3
Action = Set Value
Set Type = JavaScript Expression
JavaScript Expression = ['Return1', 'Return2']
Selection Type = Item(s)
Item(s) = P1_MULTIPLE
Test it.
basically, if you want to change value(s) of the multi select list you need to pass array of value(s).
With pure jQuery (without APEX DA):
$("#P1_MULTIPLE").val(['Return2', 'Return1'])