Our customer had a specific need: they wanted to get notified when something went wrong with the job queue in their system. While there are solutions like Azure Telemetry Signal, they come with a hitch – you have to set them up on Azure, and regular users can’t do that directly in Business Central.
So, we came up with a simple solution. We figured out a way to subscribe to a standard event called ‘OnBeforeTryRunJobQueueSendNotification’ in the “Job Queue Entry” table. This event helps us know when a job queue is about to start running. By doing this, we created a simple solution to notify users when there’s an error and the job queue stops. No need for complex setups on Azure – just a direct, easy way to keep everyone in the loop.
Taking it a step further, we introduced configurations in “General Ledger setup” and “Job Queue Entry Setup.” Now, if there’s an error, the program sends out a notification email based on the general ledger setups. What’s even better? With the job queue setup, we gained control over notifications at the job level, offering a personalized touch to keep users in the loop. It’s all about making life easier in Dynamics 365 Business Central!
For more details you may refer this project https://github.com/akhileshekartha/Job-Queue-Send-Notification
Setup in General Ledger Setup
Setup in Job Queue
Sample Email
codeunit 50100 "AKH Job Queue Events"
{
[EventSubscriber(ObjectType::Table, Database::"Job Queue Entry", 'OnBeforeTryRunJobQueueSendNotification', '', true, true)]
local procedure JobQueueEmailNotification(JobQueueEntry: Record "Job Queue Entry")
var
EmailMessage: Codeunit "Email Message";
Email: Codeunit Email;
CompanyInfo: Record "Company Information";
GenLedSetup: Record "General Ledger Setup";
EmailScenario: Enum "Email Scenario";
Recipients: Text[250];
Subject: Text[250];
Body: Text[1000];
lblBody: Label 'Error occurred in job queue entry: %1 - Error Message : %2';
lblSubject: Label '%1 Job Queue Error %2';
begin
if not JobQueueEntry."AKH Notify Error by E-mail" then
exit;
if not GenLedSetup.Get() then
exit;
if not GenLedSetup."AKH Send Email Job Queue Error" then
exit;
GenLedSetup.TestField("AKH Notification Email Address");
CompanyInfo.get();
if JobQueueEntry.Status <> JobQueueEntry.Status::Error then
exit;
// Create a formatted error message
Body := StrSubstNo(lblBody, JobQueueEntry.Description, JobQueueEntry."Error Message");
Recipients := GenLedSetup."AKH Notification Email Address";
// Email subject
Subject := StrSubstNo( lblSubject, CompanyInfo.Name, JobQueueEntry.Description);
EmailMessage.Create(Recipients, Subject, Body, true);
Email.Send(EmailMessage,EmailScenario::Default);
end;
}
Discover more from MSDynamicsBC.com
Subscribe to get the latest posts to your email.
Great solution! I setup something similar in version 14, I used PowerShell too basically run SQL queries on the job queue table, looking for the specific event for when the queue was stuck.
Does your version look across all companies? As with mine I had to do it per company.
LikeLike
Yes will work on all companies , still you need to setup email address and setup in job queue setup
LikeLike
Great, thanks for the information. Keep up the good work 🙂
LikeLiked by 1 person