Trapping Navision Error

bhuberbhuber Member Posts: 78
edited 2005-10-03 in Navision Attain
On an insert or modify error I would like to trap the Navision error message. Is this possible?

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Sure, use the return-value to check if there was an error:

    IF NOT(rec.INSERT) THEN;

    IF NOT(rec.MODIFY) THEN;
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Beware of the fact that IF NOT INSERT is not recomended when using SQL option.

    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. :D
  • bhuberbhuber Member Posts: 78
    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.
  • SavatageSavatage Member Posts: 7,142
    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.

    http://www.mibuso.com/dlinfo.asp?FileID=356
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • bhuberbhuber Member Posts: 78
    Your code

    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.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I think it depends on what you are trying to achieve.

    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?
  • DenSterDenSter Member Posts: 8,307
    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.
  • bhuberbhuber Member Posts: 78
    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.

    Thanks
  • DenSterDenSter Member Posts: 8,307
    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.
  • SavatageSavatage Member Posts: 7,142
    **Might as well link these**
    Trapping of dialogs and error messages
    http://www.mibuso.com/forum/viewtopic.php?t=3432
  • bhuberbhuber Member Posts: 78
    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.
Sign In or Register to comment.