'How do I pass/send a triggered sequential primary key generated to the next page in Oracle Apex?

I'm trying to pass a primary key value to another page in Oracle Apex Cloud. The problem here is that the Primary Key is generated using triggers.

When I used Oracle's Apex feature set Item in branches to send in the primary key to the next page, it didn't work and caused an error because it was trying to read data from the hidden Item ( Primary Key ) in the first page which is null because the primary key is only generated after an INSERT action so the Primary Key in the form will remain empty which means I can't retrieve it using Oracle's Apex set Item feature. So I want to send the primary key that is generated after the Form has been submitted to the next Form/Page.

I've searched around for a workaround this problem but can't seem to figure it out myself. I saw a method using "Return Key as Item" to send in the primary key to the next page but the explanation wasn't really detailed ( at the very least to me ) so I don't even know where to start or how to do it.



Solution 1:[1]

You don't explain what process is creating the primary key, so I'm doing a bit of guessing here:

I'm assuming that this a region of type form that creates the row with a new primary key value. I created a region on the DEPT sample table with primary key item P1_DEPTNO

By setting the attribute "Return Primary Key after Insert" the item P1_DEPTNO will get the primary key value of the row that has been inserted and can then be passed on to another page.

enter image description here

Solution 2:[2]

You commented you're still getting an error (didn't specify which one, though).

Anyway: create a page process (let's call it GetPK) which looks like this:

:P1_ID := nvl(:P1_ID, sequence_name.nextval);

Doing so, you'll put the primary key value into :P1_ID item. Now you can use it in branch to another page and set :P2_ID to :P1_ID.

That's how it usually goes and it works OK.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Koen Lostrie
Solution 2 Littlefoot