Trapping of dialogs and error messages

ottobeottobe Member Posts: 67
edited 2004-08-12 in Navision Attain
Hi
I am trying to design a C/AL procedure for automating posting of several lines. The problem is that if there is an error on one line Navison produces an errormessage which nobody can confirm. Is it poosible to disable dialoges that need user intervention?
Even better: is it possible to trap the error and let the code decide what action to take?

Comments

  • sjansjan Member Posts: 16
    Which error do you have?

    It is always better to try to avoid errors in automation procedures.
  • DenSterDenSter Member Posts: 8,307
    ottobe wrote:
    Even better: is it possible to trap the error and let the code decide what action to take?
    Yep, you find the code that errors out and you write some more code that prevents the error from happening.

    There is no such thing in Navision as an error object, so no it is not possible to actually trap it. One way you could go however is to call a codeunit inside an IF statement.
    IF MyCodeunit.RUN THEN BEGIN
      // your code for success
    END ELSE BEGIN
      // an error occurred inside MyCodeunit
      // your code for failure
    END;
    
    If MyCodeunit errors out, it returns FALSE and you can write some code to handle that.

    HTH
  • ottobeottobe Member Posts: 67
    Hi
    The IF MyCodeunit.RUN might work for some cases, but not all. Thanks.

    To exemplify:
    I want to post lines using the Navision standard posting codeunits. My posting process is trigged automatically-no user is around. If some data is erronous on one line, Navision displays a dialog concerning bad data in a record. The problem is- the execution stops waiting for the user to click OK.
    Instead I would like to mark the error as errounous and continue to next line. And I would prefer not to modify standard Navision codeunits.
    The same applies to inbuilt Navision field validation in other circumstances.
  • DenSterDenSter Member Posts: 8,307
    ottobe wrote:
    Instead I would like to mark the error as errounous and continue to next line. And I would prefer not to modify standard Navision codeunits.
    The same applies to inbuilt Navision field validation in other circumstances.
    ok so let's assume that there's something in there that says:
    blnOK := CONFIRM('want to continue?');
    IF blnOK = TRUE THEN BEGIN
      // run some code
    END ELSE BEGIN
      // run some other code
    END;
    
    If you want Navision to only run this if there is a user to click the message, you do the following:
    IF GUIALLOWED THEN
      blnOK := CONFIRM('want to continue?')
    ELSE
      blnOK := TRUE; //or whatever else you want to program
    IF blnOK = TRUE THEN BEGIN
      // run some code
    END ELSE BEGIN
      // run some other code
    END;
    
    That's the simplest way that I can explain it.
  • kinekine Member Posts: 12,562
    edited 2004-08-06
    if you use DenSter's code, no error will be raised - false will be returned instead.

    But htere is another solution (workaround) - if you user 'Navision Timer 1.0'.Timer automation, and use it to run some code, on this automation is TimerError trigger which is raised on error and have parameter ErrorString which hold Navision error text!

    When you combine DenSter's code and Navision Timer automation, you can run posting without raising error and have tool to save error text...

    I use this for scheduled adjustment with error log (if some error is found, error is logged into some table etc.)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ottobeottobe Member Posts: 67
    Hi
    Yes I have noticed that the TimerError picks up all Errormessages when the timer is enabled, and I have actually used that as an error trap once.
    Does anybody have more experience with it?
    By the way. What is DenSter code?
  • kinekine Member Posts: 12,562
    it is code which posted user DenSter... (sorry - DenSter's code) 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ottobeottobe Member Posts: 67
    Eh..Sorry about that, DenSter.
    The problem with that is that I have to rewrite all Stndard Navision Code.
    I was thinking of an other solution:

    Write e.g. an automation server that invokes Windows (the OS) to check if a New window pops up (with some ID check).
    - From my control CU: Enable it before running a specific Code unit.
    - If a dialog pops up- kill it.
    - Report back to Navision, my Control CU

    Any comments?
  • janpieterjanpieter Member Posts: 298
    Yeah, i have a comment ..

    Good luck !
    I think you need that writing this kind of automation servers ..

    hope you now something about API programming :|
    In a world without Borders or Fences, who needs Windows and Gates?
  • janpieterjanpieter Member Posts: 298
    Maybe it isn't even possible what you want, because an automation server runs in the same proces as navision. This means that when a message pops up it will prevent your code from running to detect this same popup window.

    Though i'm not sure a message will block your code, i'm affraid it will.
    In a world without Borders or Fences, who needs Windows and Gates?
  • DenSterDenSter Member Posts: 8,307
    ottobe wrote:
    Eh..Sorry about that, DenSter.
    The problem with that is that I have to rewrite all Stndard Navision Code.
    I was thinking of an other solution:

    Write e.g. an automation server that invokes Windows (the OS) to check if a New window pops up (with some ID check).
    - From my control CU: Enable it before running a specific Code unit.
    - If a dialog pops up- kill it.
    - Report back to Navision, my Control CU

    Any comments?
    Well, now instead of rewriting all Navision code, you will write a call to your new automation object everywhere an error is called.
    Good luck :wink:
  • DenSterDenSter Member Posts: 8,307
    By the way, you dont have to rewrite all Navision code, just the code that generates unwanted errors. You could also write the error message into a global text variable and get that from the errored out codeunit after it errored out.
  • gerrypaulgerrypaul Member Posts: 10
    Before you call the codeunit to post check the fields for errors. IF you find bad data mark the record and move to the next record. I do this and it works fine.
  • awarnawarn Member Posts: 261
    Hi,

    So do you guys propose removing all of the TESTFIELDS in all of the codeunits that you are trying to automate?

    Or write another codeunit that determines whether or not the testfield will fail before you call the codeunit?

    That would be my only worry, a testfield will give a dialog box if it fails thus stopping your posting routine.

    -A
Sign In or Register to comment.