Hi All,
Is there a way I can roll back a transaction without the use of an ERROR. I am looking, in other words, for the opposite of COMMIT?
Under cetrain circumstances, I need to rollback a transaction but continue processing other things. The ERROR statement will cause a rollback but would also halt execution too.
Thanks
0
Comments
Actually it's a common problem in Navision. There is no form of exception handling of any kind. This is a serious design mistake...
Say when you want to write a new front end (such as scanner) wich sends messages to navision via the nas/msmq. You want to post a document. the posting fails. How do you send a message back to the scanner stating the problem???? ](*,)
If the codeunit fails (perhaps with error('')) you can continue with other code.
Inside the loop I update the quantities to ship, and send the Sales Header into the posting routine, inside an IF statement. Simplified, the code looks like this: If the posting routine fails, the loop is still alive and you can continue on on to the next record.
RIS Plus, LLC
Of course this may demand a lot of programming, if it is a standard posting codeunit, but for something you make yourself, it is quite feasible.
RIS Plus, LLC
Your replies have been very useful. I guess the answer is to call another codeunit for which I check the return value.
Now if that codeunit terminates with an error, that error will never show. This is so because whenever the return code of a codeunit is checked, that codeunit gets automatically cleared before and after the call, so if it fails it simply dies and there is no way to return the reason afterwards.
So, it does make sense to use a single - instance codeunit as a messenger for the error message.
So What I do is I create a global text variable called 'StatusMessage', and a function that returns its value. I set it to describe the next step, so that if the next step errors out, I can get the value of the message from the calling code.
Let me give you an example. First I have a regular codeunit, with a global Item variable called Item and a global text variable called StatusMsg. Now when you run this codeunit from the object designer, this would error out and the system would say something like "Item Unit of Measure does not exist. Values Item No=something, Unit of Measure Code='WRONG VALUE'". The Item variable would be destroyed at this point, so we can't tell any of its values. You can't catch the error itself, but you CAN use the value of the globals if you know how to do it.
The codeunit also has a function called GetMessage, that returns the value of the StatusMsg variable.
Now I declare my codeunit as a variable in another object, and I can evaluate the return value, and still access the global variable, like this:
So the codeunit errors out, but is still alive. All its variables are still there, except the one that caused the error.
The only drawback is that you will never know what exactly went wrong. There is no way to catch the actual error message in Navision. I really hope this is one of the things we'll get in the new product so we don't have to rely on these types of tricks.
RIS Plus, LLC
I tried it and it works as you describe. this behaviour however contradicts the online help that reads:
If you include the return value, the system automatically clears the variables used in the codeunit object before and after it executes the object.
Anyway, Thanks again.
The trick with setting the message first is allso brilliant in it's simplicity and effectivity.
Thanks again,
RIS Plus, LLC
I guess ignorance really is bliss sometimes
I traded my sanity for a railgun
RIS Plus, LLC