Home » Developer & Programmer » Forms » on-insert trigger
on-insert trigger [message #606181] Mon, 20 January 2014 23:43 Go to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,


I want insert new records into the emp table ,i have written on-insert/pre-insert trigger at the emp block level,It is working fine, i am not getting messages at the left bottom "1 record inserted and saved transaction" like, but the values are inserted into the emp table..

IF :System.RECORD_STATUS ='NEW' THEN
insert_record;
Commit_Form();
END IF;

/forum/fa/11637/0/

Thank You
  • Attachment: image1.png
    (Size: 19.40KB, Downloaded 3708 times)

[Updated on: Tue, 21 January 2014 00:21]

Report message to a moderator

Re: on-insert trigger [message #606192 is a reply to message #606181] Tue, 21 January 2014 01:14 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If it is "working fine" then code you posted doesn't belong to ON-INSERT or PRE-INSERT trigger because neither of them allows restricted procedures, which means that you aren't telling the truth.

Is this block a database block or a control block?

Why did you choose such a solution? Why don't you use Forms' built-in capabilities which do operations like inserts into database blocks easily.

ON-INSERT trigger is supposed to be used primarily when working with non-Oracle databases. Which database are you working with?
Re: on-insert trigger [message #606196 is a reply to message #606192] Tue, 21 January 2014 01:29 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thank You for reply Littlefoot,

I have 2 canvas(emp,emp_control), i add deptno&find in the emp_control for searching records based on the deptno ,it navigates to the emp block and displayed records. So, i have taken where clause.Firstly added on-insert trigger at the EMP(Database Block) for directly insert the records in the emp table, but it is not worked.

Now i am able to insert , update & delete the records.

My another Question is:

I select the deptno=30 & click the find button , it navigates to the database block & displayed 30th records,after the last record, i am getting frm-40102 record must be entered or deleted first, how can i remove such error's suggest me please
Re: on-insert trigger [message #606198 is a reply to message #606181] Tue, 21 January 2014 01:47 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi Littlefoot,

My find button trigger, please suggest how to avoid this message ,at the last record query "frm-40102 record must be entered or deleted first".

DECLARE 
    finalstr  VARCHAR2(5000); 
    dfinalstr VARCHAR2(5000);
    QT varchar2(10) :='''';
BEGIN 
	   --first_record;
      finalstr := 'WHERE 1=1'; 
      
      IF :EMP_CONTROL.DEPTNO IS NOT NULL THEN 
        finalstr := finalstr || 'AND DEPTNO =' || QT||:EMP_CONTROL.DEPTNO||QT;
      END IF; 

      Go_block('EMP'); 
 
      dfinalstr := Get_block_property('EMP', default_where); 

      Set_block_property('EMP', default_where, finalstr);
      
      Execute_query();
END; 
Re: on-insert trigger [message #606201 is a reply to message #606181] Tue, 21 January 2014 02:30 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
I got the solution for frm-40102 record must be entered or deleted first & FRM-40352: Last record of query retrieved.
At the form level
ON-ERROR
--------
IF ERROR_CODE=40102 THEN
 null;
ELSE
  MESSAGE(ERROR_TEXT);
  MESSAGE(ERROR_TEXT);
  RAISE FORM_TRIGGER_FAILURE;
END IF;


--if :system.record_status!='NEW' then
--create_record;
--end if;

-if error_type = 'FRM' and error_code = 40352 then
 --null;
--end if;

ON-MESSAGE
----------
IF :System.last_record = 'FALSE' THEN -->FRM-40352: Last record of query retrieved.
Next_Record; 
END IF;

[Updated on: Tue, 21 January 2014 02:31]

Report message to a moderator

Re: on-insert trigger [message #606206 is a reply to message #606201] Tue, 21 January 2014 04:03 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
When getting an error you don't expect, it is never the correct solution to write some code to hide the error.
It is always the correct solution to find what is causing the error in the first place and fix it.

You get that error when you try to navigate away from a partially entered record in a database block.
So work out what is partially entered (checking :system.record_status may help) and ensure the user is prompted to save their changes first.


As for inserting: The simplest way to get forms to insert data is to write no code. You should never, under any circumstances need an on-insert trigger. You should rarely need a pre-insert, and it should never contain the code you say you've used.
So why don't you tell us what problem you trying to solve by creating these triggers in the first place?
Re: on-insert trigger [message #606207 is a reply to message #606206] Tue, 21 January 2014 04:08 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
So why don't you tell us what problem you trying to solve by creating these triggers in the first place?


You are right, cookiemonster.. Smile Actually i added on-insert & pre-insert to insert directly into the table(EMP) from the database block canvas & i got frm-40102 error

Thank You.. Smile
Re: on-insert trigger [message #606210 is a reply to message #606207] Tue, 21 January 2014 04:23 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
You do realise that forms automatically inserts directly into tables for database datablocks without you having to write any code?
Re: on-insert trigger [message #606212 is a reply to message #606210] Tue, 21 January 2014 04:25 Go to previous message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
You do realise that forms automatically inserts directly into tables for database datablocks without you having to write any code?


Yes I did cookiemonster, with just sample form contains 2 blocks(database,control) & 2 canvas.
Previous Topic: Need help while inserting record in forms
Next Topic: cursor for loop returns all records
Goto Forum:
  


Current Time: Fri Apr 26 14:49:08 CDT 2024