Home » Developer & Programmer » Forms » Pre-Insert of Data Block doesn't work for me. (Oracle 10g Forms Builder 10.1.2.0.2 Windows XP)
Pre-Insert of Data Block doesn't work for me. [message #425376] Thu, 08 October 2009 17:34 Go to next message
fredg
Messages: 8
Registered: October 2009
Location: NZ
Junior Member
Hello everyone, I am a newbie in Oracle Forms, really need help to figure out the issue of Pre-insert trigger.

I created form DEPT by following a tutorial, then data block DEPARTMENT was generated by data block wizard. at this stage, I got everything runs well, data appears correctly. So I want to use an Oracle Sequence in datablock which should generate & display the new ID in the field when user click on icon "Insert Record"on toolbox.

Firstly, the auto_sequence runs correctly by SQL*PLUS
*********************************************
select DEPT_ID_SEQ.nextval from DUAL;
*********************************************

Then I insert code as follows in trigger PRE-INSERT of DATA BLOCK.

*****************************************************
type: trigger
object: department - Data Block Level
*****************************************************
begin
select DEPT_ID_SEQ.nextval
into :DEPARTMENT.ID
from DUAL;
end;
****************************************************

finally, I save + compile module + run form, I didn't see an auto-generated ID in the ID field once I clicked the icon "insert records".

Then I made a button call "New ID", then inserted the code above into button's trigger "WHEN-BUTTON-PRESSED", re-run the form, it works!

For my understand, the icon "Insert Record" on toolbar doesn't active the trigger "PRE-INSERT".

Why?

[EDITED by LF: removed superfluous empty lines]

[Updated on: Fri, 09 October 2009 00:52] by Moderator

Report message to a moderator

Re: Pre-Insert of Data Block doesn't work for me. [message #425400 is a reply to message #425376] Fri, 09 October 2009 00:51 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
"Insert record" button on the toolbar creates a new record in the block. PRE-INSERT trigger fires during COMMIT transaction process (i.e. once you press the "Save" button on the toolbar). Therefore, you've chosen a wrong trigger (but your conclusion was correct: "insert record" button doesn't invoke PRE-INSERT trigger).

Perhaps you could try with WHEN-CREATE-RECORD or WHEN-NEW-RECORD-INSTANCE triggers, see how they work.

Optionally, set sequence value into the "Initial value" property of the ID item as :sequence.dept_id_seq.nextval. In that case, you don't even need a trigger.
icon10.gif  Re: Pre-Insert of Data Block doesn't work for me. [message #425685 is a reply to message #425400] Sun, 11 October 2009 15:47 Go to previous messageGo to next message
fredg
Messages: 8
Registered: October 2009
Location: NZ
Junior Member
Hi Littlefoot, you are the champion! the guru! The trigger WHEN-CREATE-RECORD does work well, we should not use WHEN-NEW-RECORD-INSTANCE in this case, otherwise, these existing record willbe assigned a new ID once we click PREV or NEXT button on toolbar. I wonder why these books indicated to trigger PRE-INSERT.
I appreciate so much for your help.I am sure that I will be visiting this forum regularly, wise to provide assistance to someone once I gain the ability.

[Updated on: Sun, 11 October 2009 16:15]

Report message to a moderator

Re: Pre-Insert of Data Block doesn't work for me. [message #425736 is a reply to message #425685] Mon, 12 October 2009 01:07 Go to previous message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
As of not using WHEN-NEW-RECORD-INSTANCE trigger: well, you can overcome the problem by verifying whether ID item is null and - if so - setting its value. Something like
if :department.id is null then
   select DEPT_ID_SEQ.nextval 
     into :DEPARTMENT.ID
     from DUAL; 
end if;
Doing so, you wouldn't overwrite existing ID values.
Previous Topic: How to set the header for second page
Next Topic: How To Close Internet Explorer from Oracle Forms
Goto Forum:
  


Current Time: Fri Sep 20 10:49:45 CDT 2024