Home » Developer & Programmer » Forms » Item Level Validation checking (Oracle 10g Forms, WinXP)
icon9.gif  Item Level Validation checking [message #601441] Thu, 21 November 2013 00:46 Go to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
I have a form which is a multirecord block, in that i have an item or field name as Invoice no,
well in the 1st line of the item, i type a number 123456 and again i type the same number 123456
in the second line of that item it should throw an error that duplicate value entered,
how to acheive this it in non database block?

reason: i should not insert 2 duplicate values at a same time into the table.
Re: Item Level Validation checking [message #601446 is a reply to message #601441] Thu, 21 November 2013 02:27 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Search the board, it has been asked (and answered) previously. Here's one suggestion (a dynamic record group).
Re: Item Level Validation checking [message #601451 is a reply to message #601446] Thu, 21 November 2013 03:08 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Dear its easy

DECLARE 
	A NUMBER(1):=0;
	F_NAME VARCHAR2(35);
BEGIN 
	F_NAME:=:EMPNO;
	FIRST_rECORD;
	WHILE :EMPNO IS NOT NULL LOOP
		IF F_NAME=:EMPNO THEN 
			A:=A+1;
		END IF;
		NEXT_RECORD;
	END LOOP;
	PREVIOUS_RECORD;
	IF A=2 THEN 
		MESSAGE('DUPLICATE RECORD');
		MESSAGE('DUPLICATE RECORD');
	ELSE 
		NEXT_ITEM;
	END IF;
	END;


Better take FMB file download and enjoy

Regard
mughal
Re: Item Level Validation checking [message #601452 is a reply to message #601451] Thu, 21 November 2013 03:16 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
And which trigger are you suggesting that code should go in?
Re: Item Level Validation checking [message #601453 is a reply to message #601451] Thu, 21 November 2013 03:40 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
In key-next-item trigger itself i tried it, and also put the code in a program unit and called from the
key-next-item, from both area its fired.

I will try it in all exception and inform u....
Re: Item Level Validation checking [message #601454 is a reply to message #601453] Thu, 21 November 2013 03:49 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Dear @cookiemonster i fired it "KEY-NEXT-ITEM" tested and uploaded




Regard
Mughal
Re: Item Level Validation checking [message #601455 is a reply to message #601454] Thu, 21 November 2013 03:55 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
And to go over a conversation we had the other week - what happens if the users use the mouse to navigate out of the item? or key down? or key up? or key prev?

You can not use key-next-item for validation, it can be bypassed.
Re: Item Level Validation checking [message #601459 is a reply to message #601455] Thu, 21 November 2013 04:33 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Yes @cookiemonster you are right for mouse navigation it will be problem i given just example and also for @stalin4d.

for that we need to create timer one timer

------------------------WHEN-VALIDAT-ITEM------------form-level

DECLARE
  mughal_timer TIMER;
BEGIN
  mughal_timer:=FIND_TIMER('VALIDATE');
  IF NOT ID_NULL(mughal_timer) THEN
    DELETE_TIMER(mughal_timer);
  END IF;
  mughal_timer:=CREATE_TIMER('VALIDATE', 1, NO_REPEAT);
END; 

------------------WHEN-TIMER-EXPIRED--------------form-level
DECLARE 
	A NUMBER(1):=0;
	F_NAME VARCHAR2(35);
BEGIN 
	F_NAME:=:EMPNO;
	FIRST_rECORD;
	WHILE :EMPNO IS NOT NULL LOOP
		IF F_NAME=:EMPNO THEN 
			A:=A+1;
		END IF;
	NEXT_RECORD;
	END LOOP;
	PREVIOUS_RECORD;
	IF A=2 THEN 
		MESSAGE('DUPLICATE RECORD');
		MESSAGE('DUPLICATE RECORD');
	ELSE 
		NEXT_ITEM;
	END IF;
END;



AND THANKS


Regard
Mughal


[Updated on: Thu, 21 November 2013 04:33]

Report message to a moderator

Re: Item Level Validation checking [message #601477 is a reply to message #601459] Thu, 21 November 2013 07:22 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Yes this fires from key-next-item,
but when mouse click or just copy the context of 1st field into 2nd field and
click the save button its not working.
Re: Item Level Validation checking [message #601483 is a reply to message #601477] Thu, 21 November 2013 07:33 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I already pointed out it wouldn't work.

When-timer-expired won't work either - you'll get the message but the wrong data can still be entered.

Littlefoot's suggestion looks like your best bet but it would help if you explained why the block isn't a database block and how the data from it is inserted into the DB.
Re: Item Level Validation checking [message #601491 is a reply to message #601483] Thu, 21 November 2013 07:55 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
yeah its a database block and the item is also database item, data is keyed manually, and just saved.

[Updated on: Thu, 21 November 2013 07:56]

Report message to a moderator

Re: Item Level Validation checking [message #601496 is a reply to message #601441] Thu, 21 November 2013 08:14 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Make your mind up:

stalin4d wrote on Thu, 21 November 2013 06:46

how to acheive this it in non database block?


In that case the simple answer is to post each record as you go, use when-new-record-instance for this, then you can just put a simple select in the when-validate-item trigger to check if the value is already present.
Re: Item Level Validation checking [message #601509 is a reply to message #601496] Thu, 21 November 2013 13:42 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Friend if not yet solved your problem better you upload your .FMB an table structur we will try to solve it.

Regard
Mughal

[Updated on: Thu, 21 November 2013 13:43]

Report message to a moderator

Re: Item Level Validation checking [message #601510 is a reply to message #601477] Thu, 21 November 2013 14:00 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
stalin4d wrote on Thu, 21 November 2013 07:22
Yes this fires from key-next-item,
but when mouse click or just copy the context of 1st field into 2nd field and
click the save button its not working.


Dear @stalin4d but you did not tell us what are the problem you are facing with my 2nd suggestion when-validate-item and when-timer-expired which i uploaded with code & fmb please let me know. Yes problem could be there i accepted but i wanted to sort out that issue. what kind of problem you are facing please let me know better you upload your .FMB file




Regard
Mughal

[Updated on: Thu, 21 November 2013 14:06]

Report message to a moderator

Re: Item Level Validation checking [message #601518 is a reply to message #601510] Thu, 21 November 2013 14:57 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
when-timer-expired doesn't work for the simple reason that it isn't when-validate-item.

Validation works on the basis that if a when-validate-item fails then the item it belongs to is marked as invalid and the record can't be saved.
If when-validate-item fires a timer and the when-timer-expired fails then the item is still marked as valid and record can still be saved.

For validation to work properly it has to be done in the validate triggers.
Re: Item Level Validation checking [message #601520 is a reply to message #601518] Thu, 21 November 2013 15:13 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
@cookiemonster: but please not with these words please make your own code and post here with correct answer i would like know the exact problem and please download my fmb and run and point out where is the problem.

Regard
mughal
Re: Item Level Validation checking [message #601522 is a reply to message #601520] Thu, 21 November 2013 15:39 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
@cookiemonster i will be waiting for your correct answer with 100% proof. I would like to know where i am wrong we need correct answer from you not only with these words or suggestions please post your correct code or .FMB will be highly appreciated as i posted my above code with FMB file. Why i am asking to you b'coz i wanted to learn.

Regard
Mughal
Re: Item Level Validation checking [message #601533 is a reply to message #601522] Thu, 21 November 2013 23:08 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
mughal we cannot provide the fmb because its a govt.finance project source, so its illegal if someone find thati have posted it then problem for me.
Re: Item Level Validation checking [message #601535 is a reply to message #601533] Thu, 21 November 2013 23:23 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
MK i have checked the TABULAR_DUPLICATE_TIMER with Database table, just changed the EMP block as a database block and checked the validation, its perfectly validation as DUPLICATE RECORD, but when i just copy the first data and put into the second line and save it should not allowed into the database, this is what we need to stop, we must not allow the user to save the data which is duplicated in the columns.


EMPNO    ENAME

123       STALIN
123       MUGHAL



i should not allow to save the above data into table,
but without pressing a tab button or Enter button i should just save!

is this possible?

[Updated on: Thu, 21 November 2013 23:25]

Report message to a moderator

Re: Item Level Validation checking [message #601543 is a reply to message #601535] Fri, 22 November 2013 01:14 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
By far, the simplest solution is to create a unique index on the EMPNO column (although, it is probably a primary key column already) so - database itself won't let you save duplicates. However, that "solution" isn't very user-friendly because end users will receive ORA-00001 (DUP_VAL_ON_INDEX) which means something to you (but doesn't need to mean much to an old lady who is trying to save data she had just entered into a form).
Re: Item Level Validation checking [message #601546 is a reply to message #601543] Fri, 22 November 2013 01:31 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Littlefoot wrote on Fri, 22 November 2013 12:44
By far, the simplest solution is to create a unique index on the EMPNO column (although, it is probably a primary key column already) so - database itself won't let you save duplicates. However, that "solution" isn't very user-friendly because end users will receive ORA-00001 (DUP_VAL_ON_INDEX) which means something to you (but doesn't need to mean much to an old lady who is trying to save data she had just entered into a form).


Yes if primary key or unique key constraints given means the problem will be solved but,
thats not possible because for some reasons in the future they will give same empno and that time
it should allow to save the same data.

so any other solution little?
Re: Item Level Validation checking [message #601552 is a reply to message #601522] Fri, 22 November 2013 02:00 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
@cookiemonster and @stalin4d This is my Final fmb this is 200% working TESTED and uploaded for @cookiemonster in my above when-validate-timer code/fmb was 98% working only 2% problem was there which i found my self and sort it out. and as far as concern KEY-NEXT-ITEM yes i already told you that if mouse navigation it will create problem otherwise there is no problem with the code/logic. The problem was only for the TRIGGER. You know my target is always problem should be solved for those who needs our help nothing else.



Best Regard
Mughal Cool
Re: Item Level Validation checking [message #601557 is a reply to message #601552] Fri, 22 November 2013 02:55 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
@mughals_king - I don't have a working form builder installation at the moment, so I won't be creating any fmbs. So you're going to have to make do with words and suggestions.

I already stated the correct solution: use post and a select statement in when-validate-item.

A bit more detail:

POST:

If you run an insert statement in sqlplus a row is inserted into the DB but not committed. It's visible to your session only and no other.
If you perform a commit it's made permanent and becomes visible to everyone else, if you rollback it's gone as though it never existed.

Post tells forms to send the required insert or update commands for the block changes to the DB, without a commit. So it does the same as the above. So the records you already entered are in the DB, but only your forms session can see them. If you click on save then become permanent. If you exit the form and say you don't want to save changes they are rolled back.

So if you put a post in when-new-record-instance, wrapped in an if statement to check form or block status to see if there are any outstanding changes to send to the DB, you can then write a simple when-validate-item trigger, which will look something like this:

DECLARE

l_exists   VARCHAR2(1);

BEGIN

  SELECT null
  INTO l_exists
  FROM emp
  WHERE empno = :block.empno;
  
  message('Emp No already exists');
  message('Emp No already exists');
  
  raise form_trigger_failure;
  
EXCEPTION WHEN no_data_found THEN

  --No duplicates, not a problem
  NULL;
  
END;
Re: Item Level Validation checking [message #601559 is a reply to message #601557] Fri, 22 November 2013 04:05 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
@cookiemoster's Example code. This is not fulfill the requirement of @stalin4d as you knew and it does not match with @stalin4d requirement your code will check when only data already saved in table does not suits for multirecordblock specially in the case of @stalin4d's demands.

Empno
101---already saved data

your code will check if 101 is already exist in the table then there will be message "already exist" it won't to go for next item please check my above fmb if you are having a form builder 6i or 10g or take this FMB to anywhere for checking purpose your suggestion is alwayz appreciable this fmb which i uploaded this will fulfill the requirement of @stalin4d. now my .FMB won't allow you even copy from first line to 2nd line anyway you have a good knowledge i never denied this i alwayz acknowledge if any body giving a good suggestions and you are my good FORUM friend and alwayz will be your are also helping the peoples who needs your helps and my self is doing the same job.



Thanks & best regards
Mughal



[Updated on: Fri, 22 November 2013 04:08]

Report message to a moderator

Re: Item Level Validation checking [message #601562 is a reply to message #601559] Fri, 22 November 2013 04:12 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
if you don't have form build please see this picture

Regard
Mughal
Re: Item Level Validation checking [message #601563 is a reply to message #601559] Fri, 22 November 2013 04:15 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
mughals_king wrote on Fri, 22 November 2013 10:05
@cookiemoster's Example code. This is not fulfill the requirement of @stalin4d as you knew and it does not match with @stalin4d requirement your code will check when only data already saved in table does not suits for multirecordblock specially in the case of @stalin4d's demands.

If you think that then you've completely failed to understand what post does. Re-read my above post, plus the form builder help topics on the subject and if there's something you don't understand about how it works then say what.

mughals_king wrote on Fri, 22 November 2013 10:05

your code will check if 101 is already exist in the table then there will be message "already exist" it won't to go for next item

what's next item got to do with anything?

mughals_king wrote on Fri, 22 November 2013 10:05

please check my above fmb if you are having a form builder 6i or 10g or take this FMB to anywhere for checking purpose your suggestion is alwayz appreciable this fmb which i uploaded this will fulfill the requirement of @stalin4d.

If you want me to check your code then you're going to have to paste the code here in code tags. I can't open fmbs.
Re: Item Level Validation checking [message #601566 is a reply to message #601563] Fri, 22 November 2013 04:23 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Dont't be displeased friend (: leave it and sorry for all these things.




Re: Item Level Validation checking [message #601569 is a reply to message #601566] Fri, 22 November 2013 04:31 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'm not displeased, just trying to work out where the misunderstandings are.

It's up to you, but if I was you I'd learn what post is and what effect it has, it is incredably useful to addressing situations like the OP's.

When I did work with forms the entire application used post as a matter of course and it worked like a charm. We didn't get duplicates in the DB and the code to avoid them was always very simple.
Previous Topic: How to populate a Form
Next Topic: list item problem
Goto Forum:
  


Current Time: Thu Apr 25 05:09:57 CDT 2024