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?
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.
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.
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) ?
Answers
Pargesoft
NAV way is all code for business and logical must be in table trigger.
Rollback without message: ERROR('');
For this I did something like this:
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?
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.
:?: 8)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
You can prevent the trigger from running altogether by calling DELETE with a FALSE parameter: 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.
RIS Plus, LLC
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) ?