avoid duplicating records

luciana
Member Posts: 43
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
Thanks
Luciana
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
Thanks
Luciana
0
Comments
-
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;
0 -
Setting a primary key with the right field(s) always does the trick...0
-
mohana_cse06 wrote: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?0 -
I have just given an example..based on that you have to create your logic..
where do you want to have this logic? in which table and which field? what are the primary keys of that table?0 -
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.0 -
I apologize for editing this post.
I forgave to set the primary key I needed.
Problem solved.
Thanks
Luciana0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions