codeunit 50020 SendNotifification
{
trigger OnRun()
var
JobQueue: Record "Job Queue Entry";
GetJobQueueDetails: Text[2048];
begin
Clear(JobQueue);
JobQueue.Reset();
JobQueue.SetRange("Object Type to Run", JobQueue."Object Type to Run"::Codeunit);
JobQueue.SetFilter("Object ID to Run", '50003..50020');
JobQueue.SetRange(Status, JobQueue.Status::Error);
if JobQueue.FindSet() then
repeat
GetJobQueueDetails += Format(JobQueue."Object ID to Run") + ' ' + JobQueue."Object Caption to Run";
until JobQueue.Next() = 0;
if GetJobQueueDetails <> '' then begin
SentMails(JobQueue, GetJobQueueDetails)
end;
end;
local procedure SentMails(var JobQueue: Record "Job Queue Entry"; var Details: Text[2048])
var
Rec_UserSetup: Record "User Setup";
MailingList: List of [Text];
CU_Email: Codeunit Email;
CU_EmailMessage: Codeunit "Email Message";
SubjectLbl: Label 'Job Queue Failed in Business Central';
BodyLblDeptHod: Label 'Hi IT Team, <br> <br> This is to inform you in Business Central some of the job queue failed. <br> Kindly view the failed job queue %1 this by visiting <a href="%2"> </a> here.';
AppLink: Text;
begin
Clear(AppLink);
Clear(Rec_UserSetup);
Rec_UserSetup.Reset();
Rec_UserSetup.SetRange("IT Department", true);
if Rec_UserSetup.FindSet() then
repeat
if Rec_UserSetup."E-Mail" <> '' then
MailingList.Add(Rec_UserSetup."E-Mail");
until Rec_UserSetup.Next() = 0;
AppLink := GetUrl(ClientType::Web, CompanyName, ObjectType::Page, Page::"Job Queue Entries", JobQueue, true);
if MailingList.Count <> 0 then begin
Clear(CU_EmailMessage);
CU_EmailMessage.Create(MailingList,
StrSubstNo(SubjectLbl),
StrSubstNo(BodyLblDeptHod, Details, AppLink), true);
CU_Email.Send(CU_EmailMessage);
end;
end;
}