Hello Apex Expert, In Apex, I have Master Detail form where Detail part is created using Interactive Grid. This is one go form i.e. entering master and detail record on the same form. I do not have Master Report. So when I click the Save button I want to save the data in Master table as well as in Detail table. I have tried manual PL/SQL Code process but when trying to enter the data in Detail table it raises an error saying “Cannot enter NULL value in Master_Id”. I have no idea how can I capture the Master_Id for manual IG Process? Your help would be greatly appreciated. Kind Regards,
Share
Hi Bhavin,
When we create a master form on page Oracle Apex creates a default process for this to save the form.
And when we create an editable interactive grid, also a process being created by Oracle Apex.
I understand that there is happen to a separate button for an interactive grid to save the IG data. But you want this to happen with the main save button and you can do this as follows:
First, make sure that in the process tab, your IG process is placed immediately after the form process, if not then drag it there, because maybe you have a close dialog process too.
Then hide the Interactive Grid save button from the attributes toolbar settings.
Now when the user will click on the Save button, both processes will execute and the form and IG data will be saved in one go.
One thing more.
In a form, we usually have two buttons to save the data, one is CREATE and another is SAVE.
CREATE button runs SQL insert action and the SAVE button runs the SQL update action.
You need to have both buttons but you have to show them conditionally by specifying server-side conditions.
For the CREATE button, set the serverside condition as Item value is null and specify your PK column.
For the SAVE button, set the serverside condition as Item value is not null and specify the same PK column.
Make the button label Save for both the buttons. So on the form, it will appear as a single button.
Let me know if any questions.
Hi Vinish,
Many thanks for your prompt reply and providing the steps for this.
I am still struggling on this.
Could you please send me your email so I can give an access to my application?
Kind Regards,
Bhavin
Sorry, I won’t be able to work on your application, that you have to do it.
You can tell me in which part you are struggling. I will explain to you more.
When I click the SAVE button, I am getting an error – Cannot insert NULL into Master_Id.
I have tried default Save process but did not work so then I have tried manual PL/SQL Code process.
# Manual PL/SQL Code for Master
DECLARE
l_master_id master_table.master_id%type;
BEGIN
INSERT INTO master_table (col1, col2, col3)
VALUES (:P1_COL1, :P1_COL2, :P3_COL3)
RETURNING master_id INTO l_master_id;
:P1_MASTER_ID := l_master_id;
END;
# Manual PL/SQL Code for Detail
BEGIN
INSERT INTO detail (master_id, col1, col2, col3)
VALUES (:P1_MASTER_ID, :COL1, :COL2, :COL3)
RETURNING rowid into :ROWID;
END;
If you are entering the master id manually in the upper form then ok or if it depends on a sequence, then define the default value for the sequence object.
And for the grid, I am assuming that you have the master_id for the child table. Set the default value to the P1_COL1 or P1_MASTER_ID.