Error handling by NAS

einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
Hello,

I use NAV 4.03. I installed a NAS as service. It starts a singleinstance codeunit with NAVTimer. When the timer event is fired, the following code is executed:
...
REPORT.RUNMODAL("Object No.",FALSE,FALSE);
The report does execute the following for every Sales Header within a certain filter:
...
IF Codeunit1.RUN(SalesHeader) THEN BEGIN
...
IF SalesLine.FINDSET THEN
  REPEAT
    IF Codeunit2.RUN(SalesLine) THEN;
  UNTIL SalesLine.NEXT = 0;
I thought this IF XXX.RUN(Rec) THEN construction makes sure that no error can break the loop. I mean if there is an error with a certain Sales Line it should go to the next Sales Line and try to execute the codeunit with this next Sales Line as parameter. But it always ends up at the singleinstance codeunit. Even if there is an error in the first codeunit for Sales Header. What am I doing wrong?
"Money is likewise the greatest chance and the greatest scourge of mankind."

Answers

  • kinekine Member Posts: 12,562
    It seems that the NTimer has own error handling (there is OnError trigger) and it is ignoring the "silent" error which is raised when using "if codeunit.run then" construction.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    What does that mean? I know about this OnError trigger of the timer component. Do you mean this "silent" error workaround does not work for timer triggered solutions? Or do you mean it does not work if there is any code within the OnError trigger?
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • kinekine Member Posts: 12,562
    I mean it seems that it not work when the process was started from OnTimer event.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Okay! So, any suggestions how to change the code to get rid of that problem? ](*,)
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • kinekine Member Posts: 12,562
    Look into event log, which errors you see there, if it is only the error inside the codeunit which is expected or if there are other errors... just to be sure that the problem is not somewhere else...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ta5ta5 Member Posts: 1,164
    I have used the timer object ('Navision Timer 1.0'.Timer) several times in a single instance code unit run by nas.

    In the Timer-Event trigger I just put the call to the worker codeunit.
    In the TimerError-Event Trigger I put code like this
    // without enabling it again the timer event does not fire anymore
    myTimer.Interval := mySetup."My Process Inbound Monitor Interv." * 1000;
    myTimer.Enabled(TRUE);
    
    // some error handling here
    

    In these scenarios I have never used "if codeunit.run" construct.

    Hope this helps

    Thomas
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    There are no error messages within the event log. Should NAS write into the event log even if you use IF codeunit.RUN THEN construction?
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • bbrownbbrown Member Posts: 3,268
    I've used "IF codeunit.RUN THEN" with the Navision timer many times. It works just fine. I will follow the FALSE return with a GETLASTERROR call in order to log the error to a table.
    There are no bugs - only undocumented features.
  • kinekine Member Posts: 12,562
    bbrown wrote:
    I've used "IF codeunit.RUN THEN" with the Navision timer many times. It works just fine. I will follow the FALSE return with a GETLASTERROR call in order to log the error to a table.

    Yes but only if you are on NAV 5.00... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    There are no error messages within the event log. Should NAS write into the event log even if you use IF codeunit.RUN THEN construction?

    No, it shouldn't, but that there is no error in the event log is good thing and bad thing. Good that we know that there is no another uncatched error, bad is that it will not help... :-k
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bbrownbbrown Member Posts: 3,268
    kine wrote:
    bbrown wrote:
    I've used "IF codeunit.RUN THEN" with the Navision timer many times. It works just fine. I will follow the FALSE return with a GETLASTERROR call in order to log the error to a table.

    Yes but only if you are on NAV 5.00... ;-)

    That's why I've done some technical upgrades. I've got this approach running with database versions back to 3.60, but with 5.x (or higher) clients.
    There are no bugs - only undocumented features.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    bbrown wrote:
    I've used "IF codeunit.RUN THEN" with the Navision timer many times. It works just fine. I will follow the FALSE return with a GETLASTERROR call in order to log the error to a table.
    Yes, that's what I want to do. Of course not with GETLASTERROR, because I use 4.03, but I would like to post into a log table something like "There is an error in Sales Header 123456".
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • ta5ta5 Member Posts: 1,164
    If you implement your error handling in the TimerErrorEvent-Trigger you can use the ErrorText property there, so you don't have to use the GetLastError of 5.x Nav.

    Thomas
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    The OnError event of the timer is not fired each time in a loop with "IF codeunit.RUN" contruction. But that's not my problem. The execution of the report is terminated. I want the report to go to the next record and run the codeunits with the new record.

    I even tried to execute the report's functionality through a new codeunit. Same error.
    SalesHeader.SETCURRENTKEY(...);
    SalesHeader.SETRANGE("Document Type",SalesHeader."Document Type"::Order);
    ...  //some other filters
    SalesHeader.SETFILTER("Order Date",'..%1',TODAY);
    
    Codeunit1.SetHideDialog(TRUE);
    
    IF SalesHeader.FINDSET THEN
      REPEAT
        IF Customer.GET("Sell-to Customer No.") THEN
          IF NOT Customer.Blocked THEN BEGIN
            //Codeunit1.RUN(SalesHeader);
            IF Codeunit1.RUN(SalesHeader) THEN BEGIN
              HandleLines;
              COMMIT;
            END;
          END;
      UNTIL SalesHeader.NEXT = 0;
    
    // Function HandleLines
    SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");
    SalesLine.SETRANGE("Document No.",SalesHeader."No.");
    IF SalesLine.FINDSET THEN
      REPEAT
        IF Codeunit2.RUN(SalesLine) THEN;
        //Codeunit2.RUN(SalesLine)
      UNTIL SalesLine.NEXT = 0;
    

    And I commented out all code in OnRun of codeunit1. Still the same error.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Sorry guys, it was my fault. #-o There was a LOCKTABLE one codeunit above. I did not create that codeunit, so I did not pay enough attention to it.

    Back to topic: Unfortunately there is no way to get the real last error in a "IF codeunit.RUN" contruction until 5.00 and GETLASTERROR. :-k
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • bbrownbbrown Member Posts: 3,268
    Is there a reason that a technical upgrade (newer clients) can't be done here?
    There are no bugs - only undocumented features.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    No, there is no real reason. The customer only wants to spare the effort. I will suggest him to do a technical upgrade. Otherwise he has to live with this "feature". :mrgreen:
    "Money is likewise the greatest chance and the greatest scourge of mankind."
Sign In or Register to comment.