Friday 24 July 2015

Duplicate/Copy Oracle Forms line

KEY-DUPREC
---------------------------------------------------------------------------------------------------------------
APP_STANDARD.EVENT('KEY-DUPREC');
This trigger disables the default duplicate record functionality of Oracle Forms.

To process the "Edit, Duplicate Record Above" menu choice properly,
code a block-level KEY-DUPREC with execution style 'Override'.
This trigger should perform a duplicate_record, then validate or clear fields as needed.



Why Duplicate Record is Disabled by Default
----------------------------------------------------------------------------------------------------------------
By default, duplicate record is disabled at the form level. There are several reasons for this:

The special column ROW_ID is duplicated and must be manually exempted if it exists

The record is marked as valid even through the items may contain time-sensitive data that is no longer valid

Defaults are overridden

In many blocks, Duplicate Record makes no sense (modal dialogs, find blocks, etc.)

For any block where you want to enable Duplicate Record, you must write code. You must process unique keys,
possibly reapply defaults, and confirm that copied data is still valid.
None of this is done by default, and this can lead to errors or data corruption.

In general, duplicate all item values, even if the item value must be unique.
The user may wish to create a unique value very similar to the previous value.

Do not override a default if

The item cannot be modified by the user

The item must contain a specific value for a new record

The item is a sequential number and the default is the correct value most of the time

Example
------------------
A block order has items order_number and order_date which are defaulted from the sequence order_S and from SYSDATE respectively,
and which cannot be modified by the user.
The item status should contain "Open" for a new order,
but the user can change the Status to "Book" at any time to book the order.

Create your event handler procedures as follows:

PACKAGE BODY order IS
   PROCEDURE KEY_DUPREC IS
   CURSOR new_order_number IS SELECT order_S.nextval
                               FROM sys.dual;
  BEGIN
    DUPLICATE_RECORD;
    open new_order_number;
    fetch new_order_number into :order.order_number;
    close new_order_number;
    :order.status : = 'Open';
    :order.order_date := FND_STANDARD.SYSTEM_DATE;
    :order.row_id := null;
  END KEY_DUPREC;
END order;
Call your event handler procedures in:

Trigger: KEY-DUPREC on order:

order.KEY_DUPREC;