I am running a codeunit and attempting to insert a record. There are various reasons why the insert may fail. I would like to trap the specific Navision error message and set a variable equal to it. Not sure how I can do it with your code? For example, say I wanted to create an error log table with one of the fields specifically storing the Navision Error Message.
will test if Isert will work and returns an error, but how can I trap the specific error message to a variable? It would appear that I need do something like this
Variable := IF GET(Keyfields) then error
and of course this doesn't work. Again I may be missing something.
The short answer is that no you cannot trap a Navision error. There is no error object in the Navision IDE. You can program defensively and trap errors before they occur and then analyze a variable that you use to keep the error description, but that would require extensive programming.
But.... if you just do MyRec.INSERT and that fails for whatever reason, you will not be able to figure that one out in C/AL code. It is not possible to catch the error description that you see in the messagebox, unfortunately.
I was afraid you would tell me it was not possible. I could not see how to do it. So what I am going to do is attempt to test all possible errors before the insert.
Well you could tell us exactly what you are thinking of and you'd be surprised at how many different ways you could do it. We've all been where you are now, and there may be an easy way to do what you want to do.
Here is what I am doing. I am using a third party product to access Navision through the application server to insert modify etc. What I was trying to do was let Navision tell me why it could not insert or modify and then send this info back to the external source. However, since it doesn't look like I can do this, I will have to test for specific errors and then send back corresponding messages. This makes for more work and if I miss a possible error type then I have a problem.
Comments
IF NOT(rec.INSERT) THEN;
IF NOT(rec.MODIFY) THEN;
USE
IF GET(Keyfields) then
error
instead of
IF NOT INSERT THEN
Luc, do you have this document? Maybe you can put it on the download.
The document is called Tuning Navision for better performance and is from Microsoft I believe.
Let me know if you want it.
http://www.mibuso.com/dlinfo.asp?FileID=356
http://www.BiloBeauty.com
http://www.autismspeaks.org
Thanks!
IF GET(Keyfields) then
error
will test if Isert will work and returns an error, but how can I trap the specific error message to a variable? It would appear that I need do something like this
Variable := IF GET(Keyfields) then error
and of course this doesn't work. Again I may be missing something.
Thanks for your help.
There is no thing in Navision that supresses the error message and put it in a log file.
So you need to make some checks yourself.
The difficulty depends on what you are trying to insert. If you want to make a sales order, there are tons of things that can go wrong.
If you want to insert a contact, or even a posting group, things get easier.
What is it exactly you want to import and what errors do you want to prevent from happening?
But.... if you just do MyRec.INSERT and that fails for whatever reason, you will not be able to figure that one out in C/AL code. It is not possible to catch the error description that you see in the messagebox, unfortunately.
RIS Plus, LLC
Thanks
RIS Plus, LLC
Trapping of dialogs and error messages
http://www.mibuso.com/forum/viewtopic.php?t=3432
http://www.BiloBeauty.com
http://www.autismspeaks.org