Extensions 2.0 - How can I prevent OnValidate-Trigger in OnBeforeValidate?
elbartus
Member Posts: 2
Hello,
just writing a little extensions for Dynamics NAV 2018.
And therefore I got the following question in that example:
I modify Name on Vendor-Table like
modify (Name)
{
trigger OnBeforeValidate();
begin
IF CONFIRM('Do you want to prevent/skip OnValidate?') THEN
// ????????? <- is there something I can call to prevent/skip the OnValidate-Trigger (Expect of ERROR or TESTFIELD)?
end;
}
I've already tried to call EXIT there, but that just leaves the OnBeforeValidate-Trigger an does not prevent OnValidate.
Do you have an idea?
Thanks
El Bartus
just writing a little extensions for Dynamics NAV 2018.
And therefore I got the following question in that example:
I modify Name on Vendor-Table like
modify (Name)
{
trigger OnBeforeValidate();
begin
IF CONFIRM('Do you want to prevent/skip OnValidate?') THEN
// ????????? <- is there something I can call to prevent/skip the OnValidate-Trigger (Expect of ERROR or TESTFIELD)?
end;
}
I've already tried to call EXIT there, but that just leaves the OnBeforeValidate-Trigger an does not prevent OnValidate.
Do you have an idea?
Thanks
El Bartus
0
Best Answer
-
You can't. That's the 'beauty' of Extensions - you can only add to existing code.
On the other hand - what's wrong with stopping update by throwing ERROR in OnBeforeValidate in this case?
Slawek Guzek - www.yitron.co.uk
Business Central, MS SQL Server, Wherescape RED;1
Answers
-
You can't. That's the 'beauty' of Extensions - you can only add to existing code.
On the other hand - what's wrong with stopping update by throwing ERROR in OnBeforeValidate in this case?
Slawek Guzek - www.yitron.co.uk
Business Central, MS SQL Server, Wherescape RED;1 -
Hello Slawek,
In fact, it's nothing wrong to throw an ERROR. But that way, you are not able to change the behaviour of the Validation. Here: Search Name is set to Name.
But thanks, that helped me a lot!0 -
You can workaround it to some extent by creating two subscribers, one to OnBeforeValidate event and one to OnAfterValidate, both in one codeunit, set the EventSubscriberInstance property on that codeunit to Manual, and bind both subscribers manually (for example creating another subscriber subscribing to OnAfterCompanyOpen from Cu1, in another codeunit with default EventSubscriberInstance setting, handling automatic binding).
Manually bound subscribes (unlike the static-automatic ones) can preserve the object vars between calls, so you could remember the old Name in some global var in OnBeforeValidate, and put it back in OnAfterValidate in all required places - coding restoring the value in all required places manually of course, without using the Validate trigger on the field to avoid loops.Slawek Guzek - www.yitron.co.uk
Business Central, MS SQL Server, Wherescape RED;0 -
[Topic moved from 'Navision Financials' 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
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
