Error handling in Table triggers

ta5
Member Posts: 1,164
Hello experts
I have a strange bevavior in a testing scenario.
There is a table called table1, the modify trigger looks like this
There is a codeunit with this code
If the codeunit is run, guess what message appears. It's not 'my error handling', it's 'test error'.
Whats the reason for this? I thought if the return value of the modify trigger is handled by the code, the error in the respective trigger does not fire ](*,)
Thanks in advance
Thomas
I have a strange bevavior in a testing scenario.
There is a table called table1, the modify trigger looks like this
Error('test error');
There is a codeunit with this code
table1.find('-'); table1.code := table1.code + 'x'; if not table1.modify(true) then message('my error handling');
If the codeunit is run, guess what message appears. It's not 'my error handling', it's 'test error'.
Whats the reason for this? I thought if the return value of the modify trigger is handled by the code, the error in the respective trigger does not fire ](*,)
Thanks in advance
Thomas
0
Comments
-
Hi Thomas,
when you use table1.MODIFY(TRUE) it fires the OnModify trigger of the table1.
If you need to get your error message use table1.MODIFY THEN
Albert0 -
Hi Albert
Thanks, I know that I could do that. But I need to use the table trigger, because in my real life scenario there are some very complicated checks on this trigger which I cannot duplicate.
Any other ideas?0 -
Hi Thomas
Maybe you could remove the error messages in the OnModify trigger
but then when the table is updated from a form then you would probably
need these error messages.
Maybe for your scenario you could use something like the SetHideValidationDialogue of the sales header table.
Albert0 -
Thanks Albert
I will check what I can do.
But I'm still quite wondering why the error is firing when I use the return value of the trigger function. :?0 -
Hi Thomas
Even though you are using the return value it still runs all the
code in the OnModify trigger and if you have an ERROR statement this will be executed.
Albert0 -
Yes, but for example if used with codeunits this is a very handy feature, for example in
if mycodeunit.run
imho in mycodeunit there can be ANY error and they never fire if the return value is used. So I wonder why this does not work here. Additionally I think I have seen constructs likeif not insert then modify //quite not sure whether (true) was used or not
0 -
You cant do the check like that unfortunately. What you could do as a simple solution is creating a global variable you can set on the on modify trigger and a function that returns it.
The "if codeunit.run" option is only available for codeunits.0 -
Hi Thomas
Ok get your point. What you will have to do is create another codeunit to call your modifying codeunit.
i.e MyCU1IF NOT MyCU2.RUN THEN ERROR('Cannot modify my table1');
MyCU2table1.find('-'); table1.code := table1.code + 'x'; table1.modify(true) then error('my error handling');
Albert0 -
Hi Everybody
Someone other has some thoughts on this? Thanks in advance
Thomas0
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