Avoiding errors from NAS

xavigepexavigepe Member Posts: 185
Hello. I am using NAS (not as a service, but from the command line). When I execute it, if there is an error in the code I get it in the DOS window (for example, bus. posting grup is missing in vendor XXX) and Nas does not close it enters in an endless loop retriying. Is there a way to tell NAS to to retry in case of error and just close?.

Thanks,

Comments

  • JedrzejTJedrzejT Member Posts: 267
    You can add code line before Error or Message function to avoid dialog window of errors, but this block only dialog appears.

    IF GUIALLOWED THEN
    Error('errortext');
  • kinekine Member Posts: 12,562
    xavigepe wrote:
    Hello. I am using NAS (not as a service, but from the command line). When I execute it, if there is an error in the code I get it in the DOS window (for example, bus. posting grup is missing in vendor XXX) and Nas does not close it enters in an endless loop retriying. Is there a way to tell NAS to to retry in case of error and just close?.

    Thanks,

    All depends on how your NAS is working... how the process is started, if there is some neverending loop, or there is some automation (timer etc.) which will fire trigger etc. Can you be more specific, how the NAS is working?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • xavigepexavigepe Member Posts: 185
    Thanks JedrzejT your idea works. Now the "only" problem is detect everywhere where we can have errors, but we are going to try your solution.

    Kine. Our idea is having a Nas process wich is called from a bat file for different companies A and B. When Nas is executed, reads an Excel file and creates orders in the Company A, afther that the bat file executes again and then Nas is executed for company B where it also creates orders. Our problem is: if we have an error creating orders for company A, Nas is never called for company B as Nas is still open retrying execution for company A. It's a bit complicated to explain in few words. Thanks for your help.
  • ta5ta5 Member Posts: 1,164
    This are my 20cts on this topic:
    - If you need to start nas from command line, I would prefer to have different services started and stopped with net start/net stop
    - Have your code structured with a kind of master codeunit, starting the other codeunits with "if codeunitxy.run then..." This way you have a simple error handling. If you are on NAV 5.x you also have the getlasterror command to build a more advanced error handling and/or logging.

    Thomas
  • DenSterDenSter Member Posts: 8,305
    JedrzejT wrote:
    You can add code line before Error or Message function to avoid dialog window of errors, but this block only dialog appears.

    IF GUIALLOWED THEN
    Error('errortext');
    The issue that I have with this is that errors are usually there for a reason, and this suppresses the error completely if the process runs in NAS, and a bad situation could persist, with all sorts of data issues as potential result. Simply suppressing every ERROR, MESSAGE and CONFIRM for NAS is very bad advice.

    Make sure you understand why it is there, and that you develop an alternative way to handle the situation that caused the error in the first place. If the error needs to be there then you need to find a different way to handle that for NAS.
  • kinekine Member Posts: 12,562
    Please, do not use JedrzejT solution, because it is "heavy modification of the application business of whole NAV", if you conditioned the error messages. Because instead error and rollback, it will continue in process, and this is what you don't want...

    Best solution is to have separate NAS for each company (I know, it cost something, but may be it is cheaper than trying to solve the problem and possible problems connected to the solution).

    Your problem is, that when error is called during NAS initialization (in NASHandler function of CU1), the NAS will try to reinitialize...

    You need to finish the NASHandler without problem (e.g. by defining timer, runt it and the process call in the OnTimer trigger). But than you have rpoblem how to end the NAS, because there is no C/AL to stop it. But if it is running as service, you can stop it by running NET STOP command, and because the parameters are in registry, you can modify them from NAV to run with another company next time...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    Yes, solution with removing errors is VERY DANGEROUS and I recommend to NOT DO IT! Ta5 have better solution - using the codeunit.run in condition.

    The NAS is restarting if the NASHandler is ended with error. If there is no error, it continues in run until ended with ESC key or in another way.

    Better is to run the NAS as service, because you can stop it through net stop command e.g. from C/AL code when all was done... and before that, you can change the parameters of the service by changing them in registry or by starting another instance of the NAS.

    It means something like:

    1) NAS1 starts
    2) NAS1 finished, net stop NAS1, net start NAS2
    3) NAS2 starts
    etc...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • xavigepexavigepe Member Posts: 185
    Thanks for your help. Finally we have decided to make a .NET programm to control NAS execution and it's giving us good results.
Sign In or Register to comment.