Add validation code in OnValidate code of existing field by extension

navbeginner
Member Posts: 23
Hi Experts,
I was using AL for creating new table/page by extension.
I came across a requirement where I want to add an additional validation code in OnValidate trigger of a field in Item table by extension.
Can you please suggest as I kind of got stuck.
Regards
I was using AL for creating new table/page by extension.
I came across a requirement where I want to add an additional validation code in OnValidate trigger of a field in Item table by extension.
Can you please suggest as I kind of got stuck.
Regards
0
Best Answers
-
BlackTiger wrote: »You can't as far as I understand.
Really? I have not done anything with AL, but since events OnBeforeValidateEvent and OnAfterValidateEvent are there to be used from within C/AL, I suppose they must be there from AL also. In C/AL you get an additional property to choose the field, once you have chosen one of the two events mentioned before.
HTH
5 -
Of course you can!
Ex. Customer table
tableextension 70050090 CustomerExtension extends Customer
{
fields
{
modify(Name) // Modify the existing name field.
{
// Customizable properties can be changed here.
CaptionML = ENU = 'My Changed Caption';
trigger OnBeforeValidate();
begin
// Before validating customer name
end;
trigger OnAfterValidate();
begin
// After validation customer name
end;
}
}
}Follow me on my blog juhl.blog5 -
You could also create an event subscriber codeunit.
And a function with something like this:
codeunit 50000 MyEventsubscribers
{
[EventSubscriber(ObjectType::Table, Database::Item, 'OnAfterValidateEvent', 'Description 2', false, false)]
local procedure OnAfterValidateEvent(VAR Rec: Record Item; VAR xRec: Record Item)
var
begin
end;
}5
Answers
-
BlackTiger wrote: »You can't as far as I understand.
Really? I have not done anything with AL, but since events OnBeforeValidateEvent and OnAfterValidateEvent are there to be used from within C/AL, I suppose they must be there from AL also. In C/AL you get an additional property to choose the field, once you have chosen one of the two events mentioned before.
HTH
5 -
Of course you can!
Ex. Customer table
tableextension 70050090 CustomerExtension extends Customer
{
fields
{
modify(Name) // Modify the existing name field.
{
// Customizable properties can be changed here.
CaptionML = ENU = 'My Changed Caption';
trigger OnBeforeValidate();
begin
// Before validating customer name
end;
trigger OnAfterValidate();
begin
// After validation customer name
end;
}
}
}Follow me on my blog juhl.blog5 -
You could also create an event subscriber codeunit.
And a function with something like this:
codeunit 50000 MyEventsubscribers
{
[EventSubscriber(ObjectType::Table, Database::Item, 'OnAfterValidateEvent', 'Description 2', false, false)]
local procedure OnAfterValidateEvent(VAR Rec: Record Item; VAR xRec: Record Item)
var
begin
end;
}5 -
Thanks a lot experts for your valuable advice.
I will try to execute your advice and revert0 -
Hi Experts,
All your answers, helped me a lot. I kind of understood after trying out few scenarios that you can do most of the stuff by extending a page or its base table, just need think a bit on the logic. For others we need to go with an work around.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