In your daily operations, you certainly want to avoid all errors, and if they do occur, you want to be informed promptly and precisely and solve the errors as soon as possible. When working with periodic batch jobs with standard D365FO, you often run into a problem in which the error occurs, but you find it out too late or cannot find the error message. Standard batch job alerting is too basic to be useful (shows just the batch job status), and when looking for an error in the batch job log, you often see that the log is truncated when reaching infolog limits before you get the error message.
This article describes and provides a POC implementation of three improvements that can help you to make your life with batch job errors easier (please find the download link at the end of the article).
Standard Batch Job Alert Emails With Log (Per User)
To enable standard batch job alerts, first explicitly set the user email address. (Only SysAdmins can do it, but they can do it for all users.)
Then, on the Batch job form, open Alerts and enable Email notifications. Alert settings are per user and per batch job. You can also select whether you want to get just errors, cancellations, or all.
The alert email contains a standard message with batch job status and full Infolog (our extension). Email has an HTML body, so you can change its appearance by changing the code that generates HTML (see EventNotificationBatch_BJAL_Extension::getLog()).
Alerts on the Batch Job History Table
The approach described in the first section requires that every user set alerts for themself, which might often be inconvenient. The approach described here allows an admin (or a user with sufficient privileges) to create an alert rule for the target user group, which is easier to manage for more users. It uses standard alerts with Docentric improvements (included in Docentric Free Edition).
Then, create an alert rule on the Batch job history form. By default, an Alert rule condition will limit the rule to the selected batch job. You can narrow or extend the scope by changing the condition (ex., filter Status=Error). The rule can also apply to several or all batch jobs. Always use Event=Record has been created.
Set email fields, list all recipients (individual emails and user groups), and select the appropriate email template.
Set the email template as shown below and adjust it to your requirements. A sample email body is at the end of class DocBatchJobAlertETH_BJAL. All batch job alerts specific placeholders start with the prefix BJA.
When the alert is triggered, all recipients will get the email.
Export (Large) Batch Job Logs to Excel
When investigating batch job errors, you are often frustrated that the batch job ended in Error status, but you do not see the error as the log is truncated at the infolog maximum number of lines. To overcome this limitation, we have implemented the Export log button on the Batch job history form. It exports the full batch job log to Excel, which is also convenient for searching and further analysis.