Breaking-out from a trigger

mehroz
Member Posts: 12
Can anyone tell me how to break-out from OnDelete() trigger without the Error(ErrMessageText) function.
e.g
e.g
OnDelete() If myCondition = True Break the trigger(i.e. dont delete the record)
0
Answers
-
Why don't you want to show a message? If you tell more about your case we can find a more suitable method.Ufuk Asci
Pargesoft0 -
Hi
NAV way is all code for business and logical must be in table trigger.
Rollback without message: ERROR('');0 -
Actually I am trying to run some code after these OnDelete, OnInsert, OnModify triggers have been completed; i.e. I want some OnAfterDelete, OnAfterInsert and OnAfterModify triggers.
For this I did something like this:OnDelete() Trigger { some code here } Delete; //manually delete the row from the table { since the row has been deleted so now this block will have the same effect as some OnAfterDelete trigger }
The problem with the above logic is that after the code in OnDelete trigger is completed, navision also tries to delete the same row that has already been deleted with my Delete statement above and so I get a 'row not found error'. So i want navision to break-out from this trigger as i have manually handled it. Also, since no error has been raised and the row has been deleted successfully so i dont want to annoy user with some error message. Can u have a solution for this?0 -
Hi Yaroslav
Thanks for your solution. However it didnt solve my problem since the Error(''); statement rollbacks the changes and I just wanted Navision to do nothing since I have handled the event myself.0 -
Something like:
If MyCondition then Exit;
:?: 8)0 -
Why would you want to delete the record when that is handled by the OnDelete trigger itself? As soon as the trigger ends, the record gets removed from the database. Once you go into the trigger, there's no going back. I think when you delete the record as part of the OnDelete trigger, you'll get an error message saying 'record doesn't exist' or something.
You can prevent the trigger from running altogether by calling DELETE with a FALSE parameter:MyRecord.DELETE(FALSE); // deletes and does not run OnDelete MyRecord.DELETE(TRUE); // deletes and runs OnDelete
I think what you will want to do is copy the code that you need from the OnDelete trigger and make that part of the code that actually deletes the record.0 -
Do not put Rec.DELETE statement in Rec's own OnDelete trigger.
On Delete trigger is issued right before the record is going to be deleted so you dont need to delete that record in the code - it will be deleted right after you exit the trigger.
What is exactly you trying to do after deleting the record ? Why cant that code be executed before the record is deleted ? You understand that after the record is deleted you will not know what record was deleted (unless you save somewhere its primary key values). IF you cant execute your code in onDelete trigger then probably you will need at end of the trigger set some boolean variable to true and check that variable periodically.
Are you sure you want to do your code on table level and not on interface level (i.e on a certain form) ?0 -
Thanks for all of your replies. I am now placing a new button to run the code that I wanted to run in some sort of OnAfterDelete() trigger.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