Master Detail Copy/Duplicate Problem [message #168461] |
Thu, 20 April 2006 09:52 |
vinodkumarn
Messages: 60 Registered: March 2005
|
Member |
|
|
Hi all,
I have a master and detail form. I click on a master record and i say duplicate and the system will create a new master record(duplicating). Now the requirement is when i click on a Master record and say Duplicate, the system should create a new Master record and also should Duplicate the Details associated with it, i mean if i say duplicate a master which has 2 details records, the system should duplicate the master as well as the details.
How do i do this, can anyone help me
Thanks
Kumar
|
|
|
Re: Master Detail Copy/Duplicate Problem [message #168533 is a reply to message #168461] |
Thu, 20 April 2006 20:53 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
The reference manual has the following DUPLICATE_RECORD example:/*
** Built-in: DUPLICATE_RECORD;
** Example: Make a copy of the current record and increment
** the "line_sequence" item by one.
*/
DECLARE
n NUMBER;
BEGIN
/*
** Remember the value of the 'line_sequence' from the
** current record
*/
n := :my_block.line_sequence;
/*
** Create a new record, and copy all the values from the
** previous record into it.
*/
Create_Record;
Duplicate_Record;
/*
** Set the new record's 'line_sequence' to one more than
** the last record's.
*/
:my_block.line_sequence := n + 1;
END; Try this version assuming master block is 'MSTR' and detail block is 'DTL' with fields 'field1', 'field2', and 'field3'./*
** Built-in: DUPLICATE_RECORD;
** Example: Make a copy of the current record and increment
** the "line_sequence" item by one.
*/
DECLARE
n NUMBER;
BEGIN
/*
** Remember the value of the 'line_sequence' from the
** current record
*/
n := :my_block.line_sequence;
/*
** Create a new detail records using new primary key.
*/
insert into detail_table
select n + 1 field1,
field2,
field3
from detail_table
where field1 = mstr.field1;
/*
** Create a new record, and copy all the values from the
** previous record into it.
*/
Create_Record;
Duplicate_Record;
/*
** Set the new record's 'line_sequence' to one more than
** the last record's.
*/
:my_block.line_sequence := n + 1;
/*
** Now show the detail records.
*/
go_block ('dtl');
go_block ('mstr');
END;
David
|
|
|