Validation of several fields

MortenSteengaard
Member Posts: 144
Hi experts,
I use a Business Central wave 2 - fall 2020 on-premise.
I have made a table extension for "Purchase Line" and a page extension for "Purchase Order Subform". I have added a few new fields in those two.
I need to add some validation that depend on what item the user enter into the "No." field. So if the user enters "Item A", my validation demands that my new fields must be entered also. But if the user enters "Item B", my validation should not give an error message.
I have made my validation on the trigger "OnBeforeInsert" in the table extension. It works fine.
The problem is that if I call my validation in the trigger "OnBeforeModify", then I get the error message when the user changes "No." from "Item B" to "Item A". It says that the user has to enter values in the other fields, but the user has not moved to those fields yet. The problem must be that "OnBeforeModify" is called while the user is standing on the same record in the list page.
It is important that the user does not leave the line with bad data.
Is there another trigger/event, that I should use? (In AX there is a method that is called when a user tries to leave a record.)
Or can I see somehow what the user is doing, so that my validation is called sometimes when the "OnBeforeModify" trigger is activated, and sometimes my validation is not called?
Table extension and page extension:
I use a Business Central wave 2 - fall 2020 on-premise.
I have made a table extension for "Purchase Line" and a page extension for "Purchase Order Subform". I have added a few new fields in those two.
I need to add some validation that depend on what item the user enter into the "No." field. So if the user enters "Item A", my validation demands that my new fields must be entered also. But if the user enters "Item B", my validation should not give an error message.
I have made my validation on the trigger "OnBeforeInsert" in the table extension. It works fine.
The problem is that if I call my validation in the trigger "OnBeforeModify", then I get the error message when the user changes "No." from "Item B" to "Item A". It says that the user has to enter values in the other fields, but the user has not moved to those fields yet. The problem must be that "OnBeforeModify" is called while the user is standing on the same record in the list page.
It is important that the user does not leave the line with bad data.
Is there another trigger/event, that I should use? (In AX there is a method that is called when a user tries to leave a record.)
Or can I see somehow what the user is doing, so that my validation is called sometimes when the "OnBeforeModify" trigger is activated, and sometimes my validation is not called?
Table extension and page extension:
tableextension 50103 PurchaseLine extends "Purchase Line" { fields { field(50000;"My Field";Integer) { DataClassification = ToBeClassified; Caption = 'The field'; } } trigger OnBeforeInsert() begin //ValidateMyField(); Message('OnBeforeInsert table'); end; trigger OnAfterInsert() begin Message('OnAfterInsert table'); end; trigger OnBeforeModify() begin Message('OnBeforeModify table'); //ValidateMyField(); end; trigger OnAfterModify() begin Message('OnAfterModify table'); end; }
pageextension 50103 PurchaseOrderSubform extends "Purchase Order Subform" { layout { addbefore("Quantity") { field("My Field"; Rec."My Field") { ApplicationArea = All; ToolTip = 'Something'; } } } }
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