Inserting on Master Detail form

Hello,
I have created two tables. One I'm using as my master form and the other for my detail form.
Table 1
CREATE TABLE AGENCY (
AGY_ID NUMBER (9) NOT NULL,
AGY VARCHAR2 (1) NOT NULL,
AGY_DESC VARCHAR2 (10) NOT NULL,
AGY_DESC_LONG VARCHAR2 (100),
CONSTRAINT PK_AGENCY
PRIMARY KEY ( AGY_ID ) )
There is post insert trigger on AGY_ID using a sequence:
CREATE OR REPLACE TRIGGER PORTAL30.AGY_ID_PI
BEFORE INSERT
ON AGENCY
FOR EACH ROW
Begin
If inserting and ( :new.AGY_ID is null ) Then
select AGY_ID.nextval into :new.AGY_ID from dual;
End If;
End;
Table 2
CREATE TABLE OFFICECODE (
OFF_ID NUMBER (9) NOT NULL,
OFF_DESC VARCHAR2 (4) NOT NULL,
AGY_ID NUMBER (9) NOT NULL,
OFF_DESC_LONG VARCHAR2 (100),
CONSTRAINT PK_OFFICECODE
PRIMARY KEY ( OFF_ID ) )
There is a Foreign Key on OFFICECOD.AGY_ID TO AGENCY.AGY_ID:
ALTER TABLE OFFICECODE ADD CONSTRAINT OFF_AGY_ID_FK
FOREIGN KEY (AGY_ID)
REFERENCES PORTAL30.AGENCY (AGY_ID) ;
There is post insert trigger on AGY_ID using a sequence:
CREATE OR REPLACE TRIGGER PORTAL30.OFF_ID_PI
BEFORE INSERT
ON OFFICECODE
FOR EACH ROW
Begin
If inserting and ( :new.OFF_ID is null ) Then
select OFF_ID.nextval into :new.OFF_ID from dual;
End If;
End;
I create a MD form in Portal 3.0.9.8.0 just fine. However I cannot insert the master and the detail at the same time because I get the following error:
Error: An unexpected error occurred: ORA-01400: cannot insert NULL into ("PORTAL30"."OFFICECODE"."AGY_ID") (WWV-16016)
If I create the Master record 1st, then add the detail records it works fine. But how do I insert the Master and the detail records at the same time?
Thanks,
Martin

Martin,
I had the same problem and with the help of some other folks in the forum I came up with this. It goes on the save button, plsql event handler. You'll see the 'doSave' call at the end of the procedure. It checks the value of the Master Action List and if it is 'INSERT' then sequence.nextval will be selected into v_master_id and then inserted into the table. Let me know if you have any questions. It probably needs a little clean up and some functionality for delete but so far I haven't had any problems with it.
DECLARE
v_master_id number(10);
v_masteraction varchar2(10);
v_detailaction varchar2(10);
BEGIN
v_masteraction := p_session.get_value_as_varchar2(p_block_name=> 'MASTER_BLOCK', p_attribute_name=>'_MASTER_ACTION');
IF (v_masteraction = 'INSERT') THEN
select rfi_admin.rasset_qc_master_seq.nextval into v_master_id from dual;
p_session.set_value
(p_block_name => 'MASTER_BLOCK'
,p_attribute_name => 'A_ID'
,p_index => 1
,p_value => v_master_id
FOR i in 1..g_max_det_rec LOOP
p_session.set_value
(p_block_name => 'DETAIL_BLOCK'
,p_attribute_name => 'A_MASTER_ID'
,p_index => i
,p_value => v_master_id
END LOOP;
END IF;
IF (v_masteraction = 'UPDATE') THEN
v_master_id := p_session.get_value_as_varchar2(p_block_name=> 'MASTER_BLOCK', p_attribute_name=>'A_ID');
END IF;
FOR i in 1..g_max_det_rec LOOP
v_detailaction := p_session.get_value_as_varchar2(p_block_name=> 'DETAIL_BLOCK', p_attribute_name=>'_DETAIL_ACTION', p_index => i);
IF (v_detailaction = 'INSERT') THEN
p_session.set_value(p_block_name=> 'DETAIL_BLOCK', p_attribute_name=> 'A_ASSET_QC_MASTER_ID', p_index => i, p_value=> v_master_id);
END IF;
END LOOP;
doSave;
END;

Similar Messages

  • HELP: Error while insert in master-detail form!!!

    Hello
    I have created a master-detail form and when I tried to insert a new record I got an error that the field on the detail table that references the primary key on the master table can not be null. I don't understand this error because I thought that when you create a master-detail form and you insert a new record the field that make the references in the detail table to the primary key on the master table will be automatically filled, am I wrong??. Can anybody tell me what is going on??. The primary key of my master table is filled with a trigger before insert, is that the problem??.
    Please Help me is really urgent
    Ana Maria

    I am still new to this, but maybe this will help.
    1. Double check that your foreign key link definition in the detail table is referencing the correct column in the master table. If this is not present or referencing the column, this may be causing the problem. Self evident, but sometimes it is the simple things that get us.
    2. I have not used a trigger yet, but could there be validation being done in the form before the trigger is firing. Therefore, there would not be a value in the detail part of the form.
    Hope this was of some help.

  • Error ORA-01790: for INSERT in master detail form

    Gidday;
    I get the error message 'ORA-01790: expression must have same datatype as corresponding expression' when I attempt an insert operation in the detail region of a master/detail form.
    I have checked previous entries of this error I could find - as far as I can tell the parent key defaults are correct.
    It seems one of the factors could be that the tables are not within the 'home' schema for the application. I have created a similar default master detail form on the tables, with the home schema matching that for the tables. Within my major application I have ensured the correct schema is referenced in all fields (all those I could find - in the Report Attributes / Column Attributes area).
    I just cannot find which expressions are mis-matching their datatypes.
    thanks; DS

    Hi,
    According to [http://ora-01790.ora-code.com] the error is raised because "A SELECT list item corresponds to a SELECT list item with a different datatype in another query of the same set expression." Do you have any Select Lists on your page? If you do, is the "return value" of the same datatype as for the underlying field?
    One thing to try in these circumstances is to click the Debug link on the Developer's toolbar at the bottom of the page and then try to insert your record. You will get a whole stream of messages appear on the left of the page and the error should become obvious.
    You could also check that all the defaults you have set do not contain spaces or linefeeds at the end - I have seen this cause issues before.
    Andy

  • How to create Insert & Update on master-detail form JPA/EJB 3.0

    Is there any demonstration or tips how to Insert record on master-details form for JPA/EJB 3.0 with ADF binding?

    I have master-detail forms (dept-emp). I drag the dept->operations->create method to JSF page. But when I click create button, only dept form is clear and ready for insert. But emp form is not clear. How can I add create method for this?
    Can you give some example how to pass the right object to the persist or merge method so that it can save both the two objects (master-detail tables)
    Thanks
    Edited by: user560557 on Oct 9, 2009 8:58 AM

  • How can I insert in the table detail of a master/detail form??

    Hello, I have created a master/detail form from the assistant, and with the code generated by APEX I do not manage to insert a row in the table detail, I press the button 'Add Row' and refill information, when I press the button ' to apply changes ' me the following mistake appears:
    'Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-20001: ORA-20001: Current version of data in database has changed since user initiated update process. current checksum = "C85B64D53C8D63E9D3EE83B82728DFA3", item checksum = "244B1FED90DF5CC5B0DDB6728F4D02DD"., update "CRM_ADMIN"."ASIGNACIONES_AM_CONTACTOS" set "SECUENCIA" = :b1, "CODIGO" = :b2, "NOMBRE_CLIENTE" = :b3, "NOMBRE" = :b4, "COMENTARIOS" = :b5, "CODIGO_COMERCIAL" = :b6'
    How I can solve and be able to insert in the table it detail?
    Thanks

    Hi Law,
    Text in a shape or a text box will not feature in the table of contents.
    To get a colour behind your titles, type them into your document (not a shape). Format as Heading or some other paragraph style the TOC will recognise.
    Select the title text and Format Panel > Text > Font > Gearwheel > Advanced Options.
    Choose Character Fill Color and choose a colour from the palette (left) or colour circle (right).
    Example Titles (all on the same page for a smaller screen shot).
    Chapter 3 (in a coloured Text Box or Shape) does not appear in the TOC:
    Hint for cheats :
    To give the titles a wider Character Fill Colour, add some Tab characters before and after.
    Regards,
    Ian.

  • Insert error in master-detail form

    Probably a stupid question. When I populate the master block of
    a master detail form from an LOV, I am asked to save the form.
    Since the information is loaded from the LOV, there are no
    changes to save. If I answer yes, it gives an Insert error due
    to the primary key violation in the master block table. If I
    answer no, it opens the detail block and gives the correct
    information. The problem is that when I enter information into
    the detail block and try to save it, I get the same error
    message regarding the primary key violation in the master block.
    The form works fine if I do not populate the master block from
    the LOV (or from select statements in triggers). Any suggestions
    will be appreciated.
    LS

    Hi,
    Check for the form or block status.Looks like the status has
    changed.Thats why u r getting the message.If any of the base
    table item has changed then u will get such a message.Try
    working on this an check it out.
    Thanks
    Vinod

  • Inserting records in master detail form

    I am moving an existing Webdb Application to portal. In the application there is a master detail form along the following lines
    Dept Id: 10
    Dept Name: IMS
    Employee ID Employee Name etc
    1586 Julie Wilks
    Currently users can insert/update/delete detail lines. When inserting, the dept_id foreign key is automatically inserted into the dept_id column in the detail table. My understanding is that for some reason this does not happen in portal. Instead, the user is expected to input any foreign keys manually. As this could lead to all sorts of problems I'd rather not have to do this.
    Has anyone found a means to get around this problem?
    If solutions have already been posted, please point me in the right direction as a search on the forum hasn't come up with anything.
    Many thanks,
    Julie Wilks

    Hi,
    Am I the only one having this problem?
    Thanks,
    Diana

  • Master detail form initial insert issue on details sub-region

    Hello,
    I created a master detail form with report which should do insertion on master and detail region/subregion.
    On insert mode I enter with data master and detail block, when I press "Create" button, insertion happens only on master block (order table) not and on detail block (order_item table).
    On EDIT mode it does insertions/updates on master and detail block without problems.
    Application Express 4.2.1.00.08
    Oracle Database 11g Express Edition Release 11.2.0.2.0
    I appreciate your help.
    Regards

    Something like this should do the work:
    CREATE OR REPLACE TRIGGER order_item_table_tr
       BEFORE INSERT
       ON order_item_table
       FOR EACH ROW
    BEGIN
       IF :NEW.order_id IS NULL
       THEN
          :NEW.order_id := v ('P1_ORDER_ID');
       END IF;
    END order_item_table_tr;
    /Make sure the Automatic Row Processing (DML) of the order table returns key into item > Return Key Into Item > P1_ORDER_ID (or however the primary key of the order table is named)
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Inconsistent inserts into detail table of master-detail form

    Hello,
    [I am not sure if this is a bug or user error, so I've also put this in the bug tracking system.  Apologize for the 'duplication']
    I have a master-detail form: Orders is the master, and Order_Details is the detail. I have noticed some inconsistent behavior when inserting the detail information.
    On occasion, the row will be inserted, and a null value will get inserted into the database for the first column of the detail table; all the other data values will be inserted fine. There doesn't seem to be any pattern to when it happens. I wrote down the following test steps:
    1. Enter new order information and click 'Create'
    2. Click 'Add Row' button so can add order detail info
    3. Enter detail row information
    4. Click 'Add Row' (I do this so I can see the success message that the detail data was actually inserted)
    5. Click 'Apply Changes' at the master level.
    I ran a query on the order details table and saw that the data inserted correctly. Then I ran the following test:
    1. Enter new order information and click 'Create'
    2. Click Add Row button so can add order detail info
    3. Enter detail row information
    4. Click 'Add Row' (success message appears that detail was inserted)
    5. Enter second detail row information
    6. Click 'Add Row' (success message appears that detail was inserted, however, now in the first column of that second detail row - the product name field/column - the data does not appear. I only see my null text value. The data in the first detail row is all correct)
    7. Enter third row detail information
    8. Click 'Add Row' (success message appears that detail was inserted, and this row's information appears correctly, as does the first row's, but the second row is still showing a null value for the product name column)
    9. Click 'Apply Changes' to get out of the form
    A query of the order details table shows that a null value (-) has indeed been inserted into the table for the product name column of the second detail row.
    This behavior also happens when I don't have a null value for the LOV (i.e., it defaults to the first row of the lookup table).
    Has anyone seen this before? Am I entering the data incorrectly?
    Thanks.
    -melissa
    Message was edited by:
    mblakene

    having the some problem. Any help with this ??
    milowski were you able to solve it ? can you share the information.
    Thanks

  • Insert multiple row of BLOB using Master Detail Form

    Hi,
    I try to insert multiple photos in a master detail form (just like we upload attachments when sending email), but it seems that the Tabular Form doesn't support adding a row with BLOB. I have searched the User's Guide and API Reference, but no answer on this issue.
    Anyone can help?
    regards,
    Wei

    Many thanks,
    I find another way. I released the FK of these two tables and used the code:
    Insert into PRODUCT_INFO (TITLE) values(:P1_TITLE);
    IF ( :P1_PHOTO1 is not null ) THEN
    INSERT INTO PRODUCT_IMG(PHOTO, MIMETYPE, PROPERTY_ID)
    SELECT blob_content,mime_type, "PRODUCT_INFO_SEQ".currval
    FROM APEX_APPLICATION_FILES
    WHERE name = :P1_PHOTO1;
    DELETE from APEX_APPLICATION_FILES WHERE name = :P1_PHOTO1;
    END IF;
    IF ( :P1_PHOTO2 is not null ) THEN
    INSERT INTO PRODUCT_IMG(PHOTO, MIMETYPE, PROPERTY_ID)
    SELECT blob_content,mime_type, "PRODUCT_INFO_SEQ".currval
    FROM APEX_APPLICATION_FILES
    WHERE name = :P1_PHOTO2;
    DELETE from APEX_APPLICATION_FILES WHERE name = :P1_PHOTO2;
    END IF;
    The disadvantage is that I have to set a certain number of items for inserting photos; the max numbers of uploaded photos cannot decided by users.
    Regards.

  • Adding button to report to link to master detail form

    I want to add a button to a report to direct me to a blank master detail form to insert a new record. I have used the following code in the additional PL/SQL code section:
    htp.formopen('PORTAL30.wwa_app_module.new_instance?p_moduleid=1271601405');
    htp.formsubmit('p_request','Create New');
    htp.formClose;
    When I click this I get 'Page Not Found'.
    But if I hit refresh I am directed to the correct form with the same url.
    Any ideas on what the issue is?
    Thanks.

    Hi,
    Check this sample code.
    tables:sscrfields. "Fields on selection screens
    selection-screen function key 1.
    selection-screen function key 2.
    Initialization.
      sscrfields-functxt_01 = 'Report'.
      sscrfields-functxt_02 = 'Exit'.
    at selection-screen.
       if sscrfields-ucomm = 'FC01'.
      perform f_alv_sub.
       elseif sscrfields-ucomm = 'FC02'.
       endif.
    Hope it helps.

  • Requerying on Master Detail form

    Hi,
    Does anyone know how to set up PL/SQL code to automatically requery on a master detail form after insert/update? For example, if I insert a record on the master part of the form, I would like that record to automatically show up after the insert/update. Also, if I insert a record on the detail part of the form, I would like that record to automatically show up after an insert/update.
    Thanks,
    Martin

    Hi Krishnamurthy,
    Thank you very much for the code. The code for the most part acts like I want it to except when I initally insert a master record. In my case, I have the form set up so you have to insert a master record before you can insert any detail records. Therefore, after the user clicks save, that master record needs to come up. The code you gave me only brings up the current master record if you are inserting detail records (which is great, that is what I want it to do). I have modified the code you gave me so when a user is just inserting the master record, the master record automaticaly comes up rather than the first record in the table. However my code makes the form run slow (about 13 seconds to save). Do you know of another way that I can make the form act like I want it to. Below is my code.
    Thanks again,
    Martin
    declare
         l_msg                varchar2(255);
         l_key_value      number(10);
         l_key_value2      number(10);
         v_get_id           number(9);
         v_check_detail      number(9);
         CURSOR GET_ID IS
              SELECT MAX(A.PCH_ID)
              FROM PORTAL30.PCHEADER A;
         CURSOR CHECK_DETAILS IS
              SELECT DISTINCT B.PCD_ID
              FROM PORTAL30.PCDETAILS B WHERE B.PCD_PHC_ID = v_get_id;
    begin
         /*get the key field value from the Master Detail form to requery the details since the form will be cleared out after update */
         l_key_value := p_session.get_value_as_NUMBER(
         p_block_name => 'MASTER_BLOCK',
         p_attribute_name => 'A_PCH_ID',
         p_index => 1
         doSave;--- This is the default handler
         OPEN get_id;
         FETCH get_id into v_get_id;
         CLOSE get_id;
         OPEN check_details;
         FETCH check_details into v_check_detail;
    IF check_details%NOTFOUND
    THEN
         CLOSE check_details;
         /*get the key field value from the Master Detail form to requery the details since the form will
         be cleared out after update */
         l_key_value2 := v_get_id;
         /*get the message which is going to be displayed after update */
         l_msg := p_session.get_value_as_varchar2(
         p_block_name => 'MASTER_BLOCK',
         p_attribute_name => '_STATUS');
         /*now set the key field value in the Master Detail */
         p_session.set_shadow_value(p_block_name => 'MASTER_BLOCK',
         p_attribute_name => 'A_PCH_ID',
         p_value => l_key_value2,
         p_language => PORTAL30.wwctx_api.get_nls_language);
         WWV_MASTER_GENSYS_1(p_block_name => null,
         p_object_name => null,
         p_instance => null,
         p_event_type => null,
         p_user_args => null,
         p_session => p_session);
         /*put the message(like 'Updated one master record' ) back in the screen */
         p_session.set_value(p_block_name => 'MASTER_BLOCK',
         p_attribute_name => '_STATUS',
         p_value => l_msg);
         p_session.set_value
         (p_block_name => 'MASTER_BLOCK'
         ,p_attribute_name => '_MASTER_ACTION'
         ,p_value => 'NONE');
         p_session.save_session();
    ELSE
         CLOSE check_details;
         /*get the message which is going to be displayed after update*/
         l_msg := p_session.get_value_as_varchar2(
         p_block_name => 'MASTER_BLOCK',
         p_attribute_name => '_STATUS');
         /*now set the key field value in the Master Detail*/
         p_session.set_shadow_value(p_block_name => 'MASTER_BLOCK',
         p_attribute_name => 'A_PCH_ID',
         p_value => l_key_value,
         p_language => PORTAL30.wwctx_api.get_nls_language);
         WWV_MASTER_GENSYS_1(p_block_name => null,
         p_object_name => null,
         p_instance => null,
         p_event_type => null,
         p_user_args => null,
         p_session => p_session);
         /*put the message(like 'Updated one master record' ) back in the screen*/
         p_session.set_value(p_block_name => 'MASTER_BLOCK',
         p_attribute_name => '_STATUS',
         p_value => l_msg);
         p_session.save_session();
    END IF;
    END;

  • How to set the Master Action of a master detail form?

    Hi,
    I have a regular form navigates to a master detail form in
    insert mode. How do I make the MASTER_ACTION show up
    as "Insert" instead of "None"? If I call the Master detail form
    in auto query mode, it will show up as "Update" in the
    MASTER_ACTION. How do I make the MASTER_ACTION show up as
    "Insert" instead of "None"?
    Any ideas are highly appreciated.
    Thanks;
    Kelly.

    Just have a look over these two statements if it solves your problem
    one time where clause
    Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
    dynamic where clause
    set_block_property('BLOCK_NAME'default_where, your form itme)
    you can where clause at run time from any procedure or some triggers

  • Master-Detail Form Questions

    Master-Detail Form Questions
    I have two questions in regards to master-detail forms:
    First, the form I am working on has 25 detail rows displayed to the user. If the user has more than 25 detail records for the master, I want them to be able to add more. For instance, after they enter the 25th record, I would like a pop up window to ask them if they would like to add more detail records for this master. If they select yes, then the records they have entered would be saved and then the form would repopulate with the current master record and another empty 25 detail records.
    Second, I would like the Detail Action to be set to Insert if the user moves to a new detail row and selects an item from a combo box.
    Thanks for any and all help.
    Jeremy.

    Hi Sharmila.
    Is there a way to repopulate only the Master information without populating the detail after the 'Save' button is pressed? I have written code that uses the session variables and repopulates the form with all the data that has just been saved, but I need only the master without the detail.
    Thanks.

  • Master Detail Form - Problem using built in wizard

    Hi There
    We are working on Application express 2.2.
    We are facing problems for a master detail form using Wizard. The
    details are as follows : >>
    1) Master table : TS_ENTRY_TXN
    trans_id P.K.
    2) Detail table : TS_ENTRY_TXN_DETAIL
    a)trans_id
    b)sub_trans_id Composite P.K.(trans_id,sub_trans_id) & these are
    based on sequences.
    If i try to build a master detail form using the Wizard, the options
    for providing P.K. for master & detail are listed which we used.
    As it is a master detail form, we want to carry trans_id to the detail
    for updations/insertions which doesn't happen.
    The MRU fails with oracle error :
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1,
    ORA-01400: cannot insert NULL into
    ("TS_APEX"."TS_ENTRY_TXN_DETAIL"."ENTRY_ID"), insert into
    "TS_APEX"."TS_ENTRY_TXN_DETAIL" ( "ENTRY_ID", "SUB_ENTRY_ID",
    "SMR_ID", "TASK_ID", "SUB_TASK_ID", "TIME_SPENT", "REMARKS") values (
    :b1, :b2, :b3, :b4, :b5, :b6, :b7)
    Is there any other way to build master detail wihout wizard.
    Could you please suggest us better way to complete this task.

    If I'm reading this correctly, then one of the columns in your detail tables' primary key is also the foreign key pointing to your master table? If that's the case, then that's not supported by the wizard. For the wizard generated master-detail form to work properly, you'll have to have a foreign key column in your detail table which is not part of your detail table's primary key.
    Hope this helps,
    Marc

Maybe you are looking for

  • Standard Report, for checking the PR approval status by a certain User

    Hello Experts,                       Is there any standard report in the SAP where we can find out for the given managers, if level 1 approver is Mr. X, then which all has been approved by Mr. X and and pending with subsequent approvers? Please help.

  • [SOLVED] Long time with excessive disk access before system reboot.

    I feel I would be grateful for some help here. It's my first go at Arch Linux having used Xubuntu for several years. It may be I'm missing something obvious but then I would be happy if someone could point me in the right direction. Problem: When I d

  • My desktop doesn't fit on my screen

    My desktop and any software screens will not fit on my MacBook computer monitor anymore. Mousing to the edges of the screen will cause it to slide into view while the other edges slide out of view. I've tried changing to different screen resolutions

  • Performing temperature sweep with lakeshore 340 temperature controller

    I am working on a design project to run a temperature sweep using a lakeshore 340 temperature controller. I need it to increase in steps, wait for the temperature to stabilize and then ramp up to the next setpoint. I need to be able to repeat this pr

  • Kernal_task 100% after wake up

    hello my mbp battery went bad after i noticed that kernal_task using 100% of one of cpu core, that usually happens after it wake up from sleep. i searched for solutions but the problems still occoured so is this a bug of maverick? or did apple say an