Understanding the Use of Triggers and Record Handling in Navigate Pages for Business Central

kristiela
Member Posts: 6
in General Chat
Hello! I would like to ask you about the following code for a Navigate page: link. Could you explain the purpose of the OnInit and OnOpenPage triggers and how they are used in Navigate pages?
The solution they have used calls ToDoRec.Get() in the OnOpenPage() trigger. But what happens if the table is initially empty? This call would throw an error.
Why do we even need the ToDoRec variable? What's the logic behind calling .Get() and then .Init()? Since we're fetching it from the database, wouldn't all the fields already be initialized?
How should we handle the case where the table is empty and .Get() throws an error?
Also, why does the following code:
When we use this:
We have the following trigger in the database:
The solution they have used calls ToDoRec.Get() in the OnOpenPage() trigger. But what happens if the table is initially empty? This call would throw an error.
Why do we even need the ToDoRec variable? What's the logic behind calling .Get() and then .Init()? Since we're fetching it from the database, wouldn't all the fields already be initialized?
How should we handle the case where the table is empty and .Get() throws an error?
Also, why does the following code:
trigger OnOpenPage() begin ToDoRec.Init(); Rec := ToDoRec; CurrPage.Update(); end;prevent us from editing fields in the UI on the second step of the wizard (it's as if we have set the Editable property to false)?
When we use this:
trigger OnOpenPage() begin ToDoRec.Init(); ToDoRec.Insert(true); Rec := ToDoRec; CurrPage.Update(); end;empty records get added to the database (everything except the primary key is blank).
We have the following trigger in the database:
trigger OnInsert() var ToDoRec: Record ToDo; begin if ToDoRec."No." = '' then if ToDoRec.FindLast() then Rec."No." := IncStr(ToDoRec."No.") else Rec."No." := 'TD001'; end;Thanks in advance!
0
Answers
-
[Topic moved from 'General Chat' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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