Hi to all,
how can I avoid duplicating records in a table?
If I insert a new record, I shold check the other records and look at the values were written beforee : if I have same values I should have an error message
IF you want to do it on No. 2 field of Item table then write
No. 2 - OnValidate()
IF "No. 2" <> '' THEN BEGIN
Item_M.RESET;
Item_M.SETRANGE("No. 2","No. 2");
IF Item_M.FINDFIRST THEN
IF Item_M."No." <> "No." THEN
ERROR('Altery Entered.');
END;
IF you want to do it on No. 2 field of Item table then write
No. 2 - OnValidate()
IF "No. 2" <> '' THEN BEGIN
Item_M.RESET;
Item_M.SETRANGE("No. 2","No. 2");
IF Item_M.FINDFIRST THEN
IF Item_M."No." <> "No." THEN
ERROR('Altery Entered.');
END;
I have this code on my table:
Object Number - OnValidate()
ObjectTable.RESET;
ObjectTable.SETRANGE(ObjectTable.Nr, Rec.ObjectType);
IF ObjectTable.FIND('-') THEN
Rec.ObjectType := ObjectTable.Nr;
That I need to filter Number by Object Type..
Where I should put the code you suggested?
after "IF ObjectTable.FIND('-') THEN"
begin
lvarRec.setrange(objecttype,objecttable.Nr);
lvarrec.setrange("object number","Object number");
lvarrec.setfilter("primary key",'<>%1',"primary key");//if you modify the record and this piece of code is called, you won't get the error)
if not lvarrec.isempty then
error('already did this');
rec.objecttype := objecttable.nr;
But I suggest to have a decent primary key, so you won't have to write this code. Because:
No PK: if you insert a record in this table without calling the validation, it will be inserted without error.
PK: same but with error.
|Pressing F1 is so much faster than opening your browser| |To-Increase|
Comments
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
I have this code on my table:
That I need to filter Number by Object Type..
Where I should put the code you suggested?
where do you want to have this logic? in which table and which field? what are the primary keys of that table?
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
begin
lvarRec.setrange(objecttype,objecttable.Nr);
lvarrec.setrange("object number","Object number");
lvarrec.setfilter("primary key",'<>%1',"primary key");//if you modify the record and this piece of code is called, you won't get the error)
if not lvarrec.isempty then
error('already did this');
rec.objecttype := objecttable.nr;
But I suggest to have a decent primary key, so you won't have to write this code. Because:
No PK: if you insert a record in this table without calling the validation, it will be inserted without error.
PK: same but with error.
|To-Increase|
I forgave to set the primary key I needed.
Problem solved.
Thanks
Luciana