Error Updating 'Requested Delivery Date' Field Automatically Upon Item Insertion in New Record

isabtogumon
Member Posts: 50
Hello,
After inserting the item I want to automatically update the 'Requested Delivery Date' field (it is a new record), however, the field value shows empty in the record.
It is worth mentioning that while debugging the code, I entered the filter of the line 'if SalesLine.FindFirst() then begin':

In addition to that, when changing the registry this error is shown:

Any reason for what's happening?
After inserting the item I want to automatically update the 'Requested Delivery Date' field (it is a new record), however, the field value shows empty in the record.
It is worth mentioning that while debugging the code, I entered the filter of the line 'if SalesLine.FindFirst() then begin':

In addition to that, when changing the registry this error is shown:

Any reason for what's happening?
0
Best Answer
-
- The shown error messages are not caused by the given code (at least not directly. Messing with filters may possibly cause this error elsewhere).
- You should use a different trigger. I would probably use some trigger related to validating the "No." field.
- You should use Get to fetch a record by it's primary key, not a combination of SetRange and FindFirst.
- You must not modify the filter on records passed as Var parameter lightly. Rec.Reset() above likely causes a mess.
- You should not get the Sales Header yourself here. Use Rec.GetSalesHeader instead.
- You should not Modify() SalesLine in this way, here. You should work with Rec instead. (Not modify it's Position, but making sure your changes are passed back to the caller in the Var parameter. You do not need to get the sales line from the database at all. You should use the Rec passed in.
- Item."Lead Time Calculation" is a DateFormula. CalcDate expects a DateFormula. Pass it on without messing with it like you do.
- A DateFormula formatted as string, surrounded by angle brackets uses US form for terms of the date formula. Format uses localized forms. Building a date formula string like you do here is asking for trouble. Just use Format, if some function actually expects a date formula as string and you only have a value of type DateFormula. Use the form with angle brackets only as a literal in code, and wherever you need to store a date formula as text. Use the DateFormula type to store a date formula in the database.
- Always use Validate() and Modify(True) unless you know for sure that not using the trigger does not bypass any code that should run and running the trigger would cause problems elsewhere (e.g. validation loops).
0
Answers
-
- The shown error messages are not caused by the given code (at least not directly. Messing with filters may possibly cause this error elsewhere).
- You should use a different trigger. I would probably use some trigger related to validating the "No." field.
- You should use Get to fetch a record by it's primary key, not a combination of SetRange and FindFirst.
- You must not modify the filter on records passed as Var parameter lightly. Rec.Reset() above likely causes a mess.
- You should not get the Sales Header yourself here. Use Rec.GetSalesHeader instead.
- You should not Modify() SalesLine in this way, here. You should work with Rec instead. (Not modify it's Position, but making sure your changes are passed back to the caller in the Var parameter. You do not need to get the sales line from the database at all. You should use the Rec passed in.
- Item."Lead Time Calculation" is a DateFormula. CalcDate expects a DateFormula. Pass it on without messing with it like you do.
- A DateFormula formatted as string, surrounded by angle brackets uses US form for terms of the date formula. Format uses localized forms. Building a date formula string like you do here is asking for trouble. Just use Format, if some function actually expects a date formula as string and you only have a value of type DateFormula. Use the form with angle brackets only as a literal in code, and wherever you need to store a date formula as text. Use the DateFormula type to store a date formula in the database.
- Always use Validate() and Modify(True) unless you know for sure that not using the trigger does not bypass any code that should run and running the trigger would cause problems elsewhere (e.g. validation loops).
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