Question

I have an apex application where I want a button to trigger a dynamic action. The action would be comprised of three parts: 1. Javascript to prompt for some value 2. PL/SQL to insert a row in a table including the value from 1 3. submit page

I can get the prompt to work but when step 2 runs it does the insert using the previous value from #1. For example if I hit my button twice, the first time I get nothing inserted into that column and the second time I get the value I entered the first time I was prompted.

Javascript action:

 $x("P2_REJECT_REASON").value = prompt("Please indicate your reason for rejecting this request", "");

PL/SQL action:

begin
INSERT INTO PDD_APPROVER(PDD_ID,STATUS,REASON) 
VALUES(:P2_PDD_ID,'REJECT',:P2_REJECT_REASON);  
end;
Was it helpful?

Solution

The reason why it is always one value behind is because of your page submit. The page submit will set the session state of the item to the submitted value. When your page has rendered again and the dynamic action fires, the session state of the item is still that of the value submitted during the last page submit.

If you want the value of a page item to be available in the PLSQL code of the dynamic action, you need to submit the page item to the session state when the call occurs. Do not forget that session state does not necessarily match the value of the item on the page. The page item is on the actual rendered page on a client, while session state resides in the database on the server. Since PLSQL is code ran on the server, you need to provide the values used.
You can add the item to the "Page items to submit" field of the "Execute PLSQL" action. dynamic action - execute plsql action settings

However... Why would you first perform a plsql action and then submit the page? That is totally pointless. It'd be far better to conditionally perform a process on page submit than to first execute a piece of plsql (synchronously even!) and then submit again!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top