Home » Developer & Programmer » Forms » problems with when validate item trigger (merged 3)
problems with when validate item trigger (merged 3) [message #520395] Mon, 22 August 2011 05:27 Go to next message
0204ag
Messages: 11
Registered: August 2011
Location: Bahrain
Junior Member
hi,
i have a text field where i am putting values from an LOV and i want to check for wrong entries like if the user enters a wrong code it should display the message "wrong code".
so this is the code i am using in the when validate item trigger:

begin
declare
pc number;
begin
select count(*)
into pc
from salesman_master
where SALESMAN_CODE = :inv_hdr.salesman_code;
exception
when no_data_found then
pc := 0;

if pc is null then
fgalproc(1, 'Wrong Code Entered!');
raise form_trigger_failure;
end if;
end;
end;
But it doesn;t work, it acepts the wrong code also.
can some one please help me with the code?
thanks.
Re: problems with when validate item trigger (merged 3) [message #520403 is a reply to message #520395] Mon, 22 August 2011 05:34 Go to previous messageGo to next message
cookiemonster
Messages: 13937
Registered: September 2008
Location: Rainy Manchester
Senior Member
1) Please read and follow How to use [code] tags and make your code easier to read?
2) A query that just selects an aggregate - count, min, sum etc - can never give a no_data_found execption.
3) Checking if a variable is null immediately after you set it to 0 is pretty pointless don't you think?
Re: problems with when validate item trigger (merged 3) [message #520405 is a reply to message #520403] Mon, 22 August 2011 05:45 Go to previous messageGo to next message
ranamirfan
Messages: 535
Registered: January 2006
Location: Pakistan / Saudi Arabia
Senior Member

Dear,
Try it.
Declare
Pc number;
Begin

  Select count(*)into pc 
  From salesman_master
  Where SALESMAN_CODE = :inv_hdr.salesman_code;
  
  IF NVL(Pc,0)=0 THEN
  MESSAGE('Wrong Code Entered!');
  MESSAGE('Wrong Code Entered!');
  
  RAISE FORM_TRIGGER_FAILURE;
  END IF;
  
End;



Regards,
Irfan
Re: problems with when validate item trigger (merged 3) [message #520410 is a reply to message #520405] Mon, 22 August 2011 06:11 Go to previous messageGo to next message
cookiemonster
Messages: 13937
Registered: September 2008
Location: Rainy Manchester
Senior Member
That nvl is pointless.
I'd do it this way:
DECLARE 

  pc NUMBER;

BEGIN

  SELECT 1
  INTO pc 
  FROM salesman_master
  WHERE SALESMAN_CODE = :inv_hdr.salesman_code
  AND ROWNUM = 1;
  
EXCEPTION
  WHEN no_data_found THEN

    fgalproc(1, 'Wrong Code Entered!');
    RAISE form_trigger_failure;

END;
Re: problems with when validate item trigger (merged 3) [message #520422 is a reply to message #520410] Mon, 22 August 2011 07:59 Go to previous messageGo to next message
0204ag
Messages: 11
Registered: August 2011
Location: Bahrain
Junior Member
Thank you for the replies.
actually both the codes are working but when i enter a wrong number the message "wrong code entered"(which it is supposed to) appears 3 , 4 times and also when i start the form the message appears without entering anything.
Re: problems with when validate item trigger (merged 3) [message #520423 is a reply to message #520422] Mon, 22 August 2011 08:05 Go to previous messageGo to next message
cookiemonster
Messages: 13937
Registered: September 2008
Location: Rainy Manchester
Senior Member
Then you need to work out why the when-validate-item trigger is firing when it shouldn't.
If you're using an LOV why don't you just rely on the validate from list property instead?
Re: problems with when validate item trigger (merged 3) [message #520476 is a reply to message #520423] Tue, 23 August 2011 00:53 Go to previous message
0204ag
Messages: 11
Registered: August 2011
Location: Bahrain
Junior Member
ohk...i didn't know there was a property like that, i am new to this.
Anyways thanks alot.
Previous Topic: How improve the perfomance on form
Next Topic: java.lang.IndexOutOfBoundsException: Invalid index
Goto Forum:
  


Current Time: Sat Sep 07 13:22:37 CDT 2024