How to change previous record?

NAVision
Member Posts: 1
Hi
I want to change previous record in table (to set ending if date in current record is today). I try this code:
OnAfterGetRecord()
IF "Date From"=TODAY THEN BEGIN
Rec.NEXT:=-1;
Rec."Date To":=TODAY-1;
END;
I want to change previous record in table (to set ending if date in current record is today). I try this code:
OnAfterGetRecord()
IF "Date From"=TODAY THEN BEGIN
Rec.NEXT:=-1;
Rec."Date To":=TODAY-1;
END;
0
Answers
-
You can access previous record by doing
Rec.NEXT(-1); //it will return you the previous record.
General syntax is Rec.NEXT(Steps);
please verify my answer, if it was helpful for you. thanks.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.0 -
Why dint you used MODIFY at last??
Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
You should do it on a copy of the record, not on Rec itself. So create a variable called Rec2 for the same table and then try the following code...
OnAfterGetRecord() IF "Date From" = TODAY THEN BEGIN Rec2.COPY(Rec); IF Rec2.NEXT(-1) THEN BEGIN Rec2."Date To" := TODAY-1; Rec2.MODIFY; END; END;
EDIT: Oops - @jreynolds is correct, code amended accordingly0 -
Be careful using assignment (:=) to copy Rec to Rec2. This will only copy the values of the fields in Rec to Rec2; it will not copy settings for filters and the current key. Therefore, Rec.NEXT(-1) and Rec2.NEXT(-1) will not necessarily be the same record. It's better to use COPY so that filters and key settings are copied as well.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