Options

E-mail To Report An Error on a Job

matias_jaurematias_jaure Member Posts: 157
Hi all!, I don´t know if it is possible, is there any way if a Job in Navision fail the program send an e-mail to a given mail????

Thanks

Comments

  • zeninolegzeninoleg Member Posts: 236
    Take a look at the codeunit 397 Mail. You can use a function NewMessage in this codeunit to sent email using your standard email client.
    The only problem is that you will ahve to check manually the condition taht generates error and send email before this condition is checked in the standard code and error is raised.
    Something is wrong with my language today #-o so let me know if it helps
    Best Regards,
    Oleg
  • matias_jaurematias_jaure Member Posts: 157
    mmm... it´s not possible to send for example the Message text that the Job Scheduler log gives???
    I will check that codeunit right now
    thanks
  • David_SingletonDavid_Singleton Member Posts: 5,479
    This is quite a complex process for Navision.

    basically when a Navision process dies, its too late to send a message that it died.

    We had a client that imported invoices in from a Unix system to Navision, this was done about every hour or so. But often UNIX and windows would fight over the file, and the Navision dataport would die. It just needed to be restarted and all was fine. The dataport it self ran from a loop that looked to see if the file was there, if so imported it, and then moved the file somewhere else.

    What we did in the end is ran two Navision sessions on the machine, then between each import we commited a record to a new table, with status, so if the status was not updated to complete, the second task would wait 5 minutes, and then send an email to a provider that could redirect this to an SMS. That way the operator got a message on his cell phone when the process stopped.

    It worked great for about 6 months, but then when Navision released 2.00 they fixed up both GETLATESTVERSION and the way Navision moved files, so it ran smoothly and we didn't need the function any more.

    Anyway its a lot of work, but it is possible. Oh and now there is OnTimmer in forms, which makes it even easier.
    David Singleton
  • matias_jaurematias_jaure Member Posts: 157
    I found a little difficult to found mannualy the error and send an e-mail just before the condition is checked (?) Is it possible? so I have to checked all the possible errors, no way if the Report for example just hang up...
    let me know if I understand what you said me...

    Thanks again!
  • zeninolegzeninoleg Member Posts: 236
    Ok, let me just rephrase it.
    Lets say you have following code
    IF Record.Field1 = 'abc' THEN
      ERROR("Field cannot be 'abc'!")
    
    When the program hits the ERROR line there is no way of catching the error - program just gives a runtime error and stops. Basically NOTHING can be done after ERROR command.
    One of the solutions is to check the condition that can possibly generate error before processing ERROR line.
    So code can look like this:
    IF Record.Field1 = 'abc' THEN BEGIN
      IF Mail.NewMessage(...) THEN;  //Thius line will send your error email
      ERROR("Field cannot be 'abc'!");
    END;
    

    I know it is a lot of work to check every possible scenario to prevent generation of errors before this email can be sent but I do not think tehre is an easier way.
    In version 5 there wiill be a function to return the last error, so you can email it, but we havce what we have.

    If you will take a look at the job scheduler and the way taht those error lines get there you will see that it is all programmed in code to populate the line of the Job Scheduler, so it is not done automatically.

    Another idea. You can try to send an email every time this line in Job Scheduler is being populated.

    IF your report is hanging you will have to find a reason why it is doing that and correct it.
    Best Regards,
    Oleg
  • flfl Member Posts: 184
    If you want to check the job sheduler, you need to build a watchdog. In electronics this is mostly build at hardware level. It can be found back in PLC's, ...

    I build it in a software way to check the sheduler. I checked the sheduler jobs and I found that the longest job toke several hours, but that was only during the night. During the day it was only 3 minutes. I modified the job sheduler that after every job, a date and time field is filled on the job sheduler setup (last date and time of execution). I made a small form that is automatically opened when you open the navision application (but only for a certain user). In that form is a timer build in. Every minute a check there to see if the latest execution time of the sheduler is longer then 5 minutes, if so an alarm will sound to inform that the sheduler did stop running. Because the user never logs in during the night, i don't have problem with the long runs of the night.

    Don't use this watchdog routine on the same pc as the sheduler is running, if so you will get no messages if for exemple the sheduler isn't running no more.

    This principe of watchdog is well known to and used by many hard- and software builders.
    Francois
    Consultant-Developper

    http://www.CreaChain.com
  • David_SingletonDavid_Singleton Member Posts: 5,479
    fl wrote:
    If you want to check the job sheduler, you need to build a watchdog. In electronics this is mostly build at hardware level. It can be found back in PLC's, ...
    ](*,)

    Well if Matias didn't like it when I suggested it, you are probably wasting time repeating it. #-o
    David Singleton
  • flfl Member Posts: 184
    Sorry David,

    I did see the question, and I was so quick to answer about the watchdog functionality that I didn't read well the other proposed solutions.
    Francois
    Consultant-Developper

    http://www.CreaChain.com
  • David_SingletonDavid_Singleton Member Posts: 5,479
    :mrgreen: Interesting then that we both make the same suggestion. I would think that's a good indication that its the best way to go. Maybe Matias will give it a second thought now.

    By the way, we ran both tasks on the same machine, and never had any problems. I wrote this back in Ver 1.3 before OnTimmer exists, so it was pretty unstable in the begining, but once it was working, I never had a problem running both Navision sessions on the same machine. It was running 24/7 for years.
    David Singleton
  • MbadMbad Member Posts: 344
    zeninoleg wrote:
    easier way.
    In version 5 there wiill be a function to return the last error, so you can email it

    Nice!
  • matias_jaurematias_jaure Member Posts: 157
    edited 2007-02-05
    Sorry for the delay, I was two days off. One question, I am interesting on doing some SQL Store Procedure and check in the table Job Sheduler Manager or Job Scheduler Log, what do you think? What would be a good way to check the errors???
    Thanks to all!!!
  • ara3nara3n Member Posts: 9,258
    That is a solution as well.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.