2

How do I make AX send an alert email every time a batch job executes?

I know how to make it send an email when I change the status to waiting or withheld.

I would like to be able to set up alerts when jobs exe, error, and so on.

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
user3347022
  • 259
  • 2
  • 12
  • How do you make it send an email when you change the status and why can't you use that when the batch framework changes the status? I would use the [alert framework](https://technet.microsoft.com/en-us/library/aa497014.aspx) in AX, no customization necessary. – FH-Inway Nov 15 '16 at 11:08
  • I just create an alert rule. Field: Status Event: has changed Alert me for: All records in batch job No end date – user3347022 Nov 15 '16 at 18:52

2 Answers2

1

I don't think standard alerts will work, but you could put custom code in the BatchRun class. I wouldn't recommend it, but instead I'd suggest you create a very simple batch process that monitors whatever batch tasks you want to monitor.

If you must put code in, it looks like there are several processes that can change a Batch or BatchJob to executing, and you'd have to examine the logic more closely:

  • \Classes\BatchRun\serverGetTask
  • \Classes\BatchRun\do
  • \Classes\BatchRun\serverGetOneTask
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Do they? I vaguely remember trying it years ago when I was trying to identify a race condition. I think for errors they would, but changing to `execution`, if you look at the the code, it has all sorts of `.skipXXX` things set. I just thought I remembered it wouldn't work, and figured since the poster is discussing alerts, he must have tried them too. – Alex Kwitny Nov 15 '16 at 16:03
  • Ah, so you are still talking to me :) I was wondering when I never got a response on my answer to [your comment](http://stackoverflow.com/questions/32497849/how-to-do-unit-testing-in-microsoft-dynamics-ax-2012-in-a-real-world-project/32501796#32501796). But back on topic, I can see how alerts would not work in such a case. Seems you need a customization like you or Jan suggested to solve this. – FH-Inway Nov 15 '16 at 17:21
1

As this is not a standard option, the easy way would for the job to send the mail itself.

There are several ways to send email, SysEmailTable::sendMail comes handy:

SysEmailTable::sendMail('templateId',
                        'en-us', // Chosen language
                        'WhoYouSendThisTo@example.com', // Who you're sending the email to
                        mappings, // Your variable mappings
                        '', // Location of file attachment (server/client matters) or none
                        '' , // XML if you're using XSLT
                        true, // Traceable or not?
                        'admin', // Sending user
                        true); // Use retries?

See this blog for more information.

Tom V
  • 1,498
  • 18
  • 24
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50