Home » Developer & Programmer » Forms » Problem with trigger when-validate-item (oracle forms 10g ,windows xp pack2)
Problem with trigger when-validate-item [message #573494] Sat, 29 December 2012 12:58 Go to next message
goldray
Messages: 108
Registered: December 2012
Senior Member
Hi all ..
i want to check my item to became unique in my database and the item exist in the database ,it must be clear(this item) !! ,so i use trigger when-validate-item for this item and trigger when-timer-expired for the form global ..
this is my code :
//trigger when-walidate-item :
i number;
vTimer TIMER;
begin

IF //condition then
i := show_alert('ERROR');
/* Create a timer with a 10 Millisecond delay */
vTimer :=create_timer('TEMP',10,no_repeat);

end IF;

end;


//trigger when-timer-expired
GO_BLOCK ('name_block');

:name_block.item1:=NULL;

DELETE_TIMER('TEMP');

But in runtime ,i was this error :
FRM-40202 Field must be entered !!


thank you Smile
Re: Problem with trigger when-validate-item [message #573497 is a reply to message #573494] Sat, 29 December 2012 13:10 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Why a timer? WHEN-VALIDATE-ITEM is capable of handling such a requirement itself.
declare
  l_exists varchar2(1);
begin
  select null
    into l_exists
    from your_table t
    where t.id = :block.item_name;

  message('Such a value already exists in the database');
  :block.item_name := null;
  raise form_trigger_failure;

exception
  when no_data_found then
    -- OK, no problem - it doesn't exist
    null;
end;


However, why wouldn't you let Oracle handle that? Create a table and indicate that the item should be unique (either make it a primary key, unique key, or create a unique index on it). If you do that, Oracle won't let you save a duplicate.
Re: Problem with trigger when-validate-item [message #573500 is a reply to message #573497] Sat, 29 December 2012 13:36 Go to previous messageGo to next message
goldray
Messages: 108
Registered: December 2012
Senior Member
thank you for the answer Smile
if i let oracle handle that ,i should be fill the next item and when the boutton will be pressed ,the error message is displayed ..
i have a question , what's the function of "raise form_trigger_failure ; " ?
thank you Smile
Re: Problem with trigger when-validate-item [message #573501 is a reply to message #573500] Sat, 29 December 2012 13:41 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
FORM_TRIGGER_FAILURE is an exception; when we RAISE it, form (trigger in this case) stops the execution.

[Updated on: Sat, 29 December 2012 13:41]

Report message to a moderator

Re: Problem with trigger when-validate-item [message #573503 is a reply to message #573501] Sat, 29 December 2012 13:58 Go to previous messageGo to next message
goldray
Messages: 108
Registered: December 2012
Senior Member
thank you very much Smile
the problem is solved Smile
i have a question ,if i want to add another condition of this item (must be not null) the code will be like this ?? :
		if condition1 then
				i := show_alert('ERROR_CODE_GR');
							 :block.item1:=null;
							   raise form_trigger_failure;
end if;

							 
//condition NOT NULL
	if :block.item1 is null then
			j:=show_alert('err2');
			raise form_trigger_failure;
		end if;
	
exception
  when no_data_found then
    -- OK, no problem - it doesn't exist
    null;
		end;


thank you Smile
Re: Problem with trigger when-validate-item [message #573504 is a reply to message #573503] Sat, 29 December 2012 14:15 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
No, you don't code that. Open item's Property Palette and set its "Required" property to YES. Forms will, then, take care about it.
Re: Problem with trigger when-validate-item [message #573505 is a reply to message #573504] Sat, 29 December 2012 14:30 Go to previous messageGo to next message
goldray
Messages: 108
Registered: December 2012
Senior Member
it is already required !!
but i want to display message when this item 's null
Re: Problem with trigger when-validate-item [message #573506 is a reply to message #573505] Sat, 29 December 2012 14:34 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Forms will display it for you, don't worry.
Re: Problem with trigger when-validate-item [message #573507 is a reply to message #573505] Sat, 29 December 2012 15:19 Go to previous messageGo to next message
goldray
Messages: 108
Registered: December 2012
Senior Member
so i must to set "required" to no and create this code :
		if condition1 then
				i := show_alert('ERROR_CODE_GR');
							 :block.item1:=null;
							   raise form_trigger_failure;
end if;

							 
//condition NOT NULL
	if :block.item1 is null then
			j:=show_alert('err2');
			raise form_trigger_failure;
		end if;
	
exception
  when no_data_found then
    -- OK, no problem - it doesn't exist
    null;
		end;
Re: Problem with trigger when-validate-item [message #573508 is a reply to message #573507] Sat, 29 December 2012 15:31 Go to previous messageGo to next message
goldray
Messages: 108
Registered: December 2012
Senior Member
i know that forms handle that but i want to display error message (because i must follow the set of specification )!!
Re: Problem with trigger when-validate-item [message #573522 is a reply to message #573508] Sun, 30 December 2012 04:56 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If you don't want Forms to do the dirty job, then yes - you have to code it manually.

From my point of view, you should post actual code and - please, format it ... indentation you use is awful. If you don't know how to do that, here you go (have a look - it will take 10 seconds of your time to review it, but - if you follow the instructions - your future posts will be improved).

Code you posted doesn't need that EXCEPTION handler section at all - there's nothing there that is capable of raising the NO_DATA_FOUND.
Re: Problem with trigger when-validate-item [message #573536 is a reply to message #573522] Sun, 30 December 2012 10:06 Go to previous message
goldray
Messages: 108
Registered: December 2012
Senior Member
thank you for to advices and I will be more careful about indentation soon
Previous Topic: icon in unix forms 6i [merged 2 by jd]
Next Topic: How to get ip address in forms 6i
Goto Forum:
  


Current Time: Wed Jul 03 12:37:06 CDT 2024