Home » Developer & Programmer » Forms » prevent deletion of record (Forms [32 Bit] Version 10.1.2.0.2 (Production))
prevent deletion of record [message #454660] Thu, 06 May 2010 14:08 Go to next message
dgloeppky
Messages: 28
Registered: May 2010
Junior Member
Hello,

Form has insert and delete enabled.

I would like to prevent the deletion of a record based on some column value.

Something like:

IF (COLA value < 10) THEN
SHOW ALERT;
RECORD IS NOT DELETE
ELSE
DELETE RECORD AS NORMAL
END IF;

I want this to happen even before the record is marked for deletion, but I don't know where to put it. I tried a pre-delete trigger, but it does not work they way I want.

Re: prevent deletion of record [message #454666 is a reply to message #454660] Thu, 06 May 2010 14:49 Go to previous messageGo to next message
klat
Messages: 87
Registered: May 2009
Location: Mumbai
Member

Have you tried KEY-DELREC ?

Or you can set the block property, delete_allowed to false in when-new-record-instance based on your condition.
IF (COLA value < 10) THEN
  set_block_property('block_name',delete_allowed,property_false);
ELSE
  set_block_property('block_name',delete_allowed,property_true);
END IF;
Re: prevent deletion of record [message #454670 is a reply to message #454666] Thu, 06 May 2010 15:17 Go to previous messageGo to next message
dgloeppky
Messages: 28
Registered: May 2010
Junior Member
What would I put in the KEY-DELREC trigger?

You ARE allowed to delete records in the block, just not records that fail a conditional check, so wouldn't setting any block properties apply to all records?

Basically...

If I am on a record that will fail the check, delete is not possible, and will show an alert.

If I am on a record that will pass the check, go ahead and delete it.

Re: prevent deletion of record [message #454676 is a reply to message #454670] Thu, 06 May 2010 16:03 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
What is that "cola" thing?
-- KEY-DELREC trigger
if cola < 10 then 
   raise form_trigger_failure;
else
   delete_record;
end if;
Re: prevent deletion of record [message #454677 is a reply to message #454670] Thu, 06 May 2010 18:27 Go to previous messageGo to next message
dgloeppky
Messages: 28
Registered: May 2010
Junior Member
ColA just symbolizes 'some' column - :MYBLOCK.COLUMNA.

I assume the KEY-DELREC trigger would be on ColA item, as opposed to the block level?

I tried the following on the block level trigger and it does not work:

BEGIN
IF (:MYBLOCK.COLUMNA < 10) THEN
ALERT_HISTORICAL_RECORD;
RAISE FORM_TRIGGER_FAILURE;
END IF;
END;

If a select record/remove on a record where COLUMNA is greater than 10, nothing happens. When I commit, I get a FRM-40401 'No changes to save'.

[Updated on: Thu, 06 May 2010 18:30]

Report message to a moderator

Re: prevent deletion of record [message #454702 is a reply to message #454677] Fri, 07 May 2010 00:40 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Nothing happens? Why did you expect it to? You handled only one situation, i.e. if columna < 10 then do nothing. You *forgot* to delete a record if columna >= 10.

Compare your code with mine and, if you are careful enough, you'll notice the difference.

Besides, yes - KEY-DELREC should probably be a block level (if not, then form level) trigger.
Re: prevent deletion of record [message #454778 is a reply to message #454660] Fri, 07 May 2010 06:42 Go to previous messageGo to next message
dgloeppky
Messages: 28
Registered: May 2010
Junior Member
I thought default forms processing would kick in and the record would be deleted I thought the only trigger which overrode default forms processing (in the case delete), is the ON-DELETE trigger?

Thanks!
Re: prevent deletion of record [message #454780 is a reply to message #454778] Fri, 07 May 2010 06:47 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
KEY triggers (all of them) also override default processing.
Re: prevent deletion of record [message #454795 is a reply to message #454780] Fri, 07 May 2010 08:21 Go to previous message
dgloeppky
Messages: 28
Registered: May 2010
Junior Member
Thanks everyone... it is working the way I want now.
Previous Topic: How to move Cursor to another Item
Next Topic: Why are forms 10g Images blur on run time ?
Goto Forum:
  


Current Time: Fri Sep 20 09:23:56 CDT 2024