I want to reset Line No. when line is deleted, how can I do that?

Vesna_1
Member Posts: 23
I want to reset Line No. when line is deleted, how can I do that?
Can I use OnDelete trigger and how?
When I delete all records and want to create new, Line No. is not starting from 1. It starts from last number of deleted records.
Can I use OnDelete trigger and how?
When I delete all records and want to create new, Line No. is not starting from 1. It starts from last number of deleted records.
0
Answers
-
you can override default "Line No." value (it is incrementing with every new record no matter what)
Create function:GetNewLineNo () : integer lr_SomeRec.SETRANGE("Primary Key Field", Rec."Primary Key Field") IF lr_SomeRec.FINDLAST THEN EXIT(lr_SomeRec."Line No." + 1) ELSE EXIT(0)
Add this code to the last line of the OnInsert trigger of table:"Line No." := GetNewLineNo;
not the best practice at all but sometimes we have to do something just nice for customer, aren`t we?0 -
AutoIncrement is set to Yes0
-
Honestly speaking, it is a REALLY BAD IDEA to manually change value in AutoIncrement field. I faced with the similar issue recently, when developer tried to manually set numbers to AutoIncrement field, and we had many troubles with users. In detailed way, you can read http://bpsoftware.com/2012/12/01/microsoft-dynamics-nav-permission-error-set-identity_insert/
IMHO, as described on the link above, you have 2 options:
1. Leave AutoIncrement field alone, not trying to change it manually in any way;
2. Change AutoIncrement Property to false, and manage this field manually.Let's go!0
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