You can create a separate codeunit to send the result checking the log entry. This codeunit can be scheduled using the Job queue setting a start time. It should be executing after the desired codeunit is finished executing. For an instance, lets say the your desired codeunit is running at 22.00 and it is taking 30 mins for execution. The second codeunit which is sending the status of the execution can be scheduled around 22.30.
We have overcome this issue adopting this mechanism. The codeunit which can be used is given below. Try this.
CLEAR(strEmailBodyFormatted);
i := 1;
StartDateTime := CREATEDATETIME(TODAY,000000.01T);
EndDateTime := CREATEDATETIME(TODAY,235959T);
gtJobQueueLogEntry.RESET;
gtJobQueueLogEntry.SETFILTER(gtJobQueueLogEntry."Object Type to Run", FORMAT(gtJobQueueLogEntry."Object Type to Run"::Report));
gtJobQueueLogEntry.SETFILTER(gtJobQueueLogEntry."Object ID to Run",'*****');
gtJobQueueLogEntry.SETRANGE(gtJobQueueLogEntry."Start Date/Time", StartDateTime, EndDateTime);
IF gtJobQueueLogEntry.FINDLAST THEN
BEGIN
gtJobQueueLogEntry.CALCFIELDS(gtJobQueueLogEntry."Object Name to Run"); /
strEmailBodyFormattedstr := gtJobQueueLogEntry."Object Name to Run"
+' : Status - '+FORMAT(gtJobQueueLogEntry.Status)
+' ( '+FORMAT(gtJobQueueLogEntry."Start Date/Time")+' - '+FORMAT(gtJobQueueLogEntry."End Date/Time")+' ) '
+ gtJobQueueLogEntry."Error Message";
i := i + 1;
END;
IF gtJobQueueLogEntry.COUNT = 0 THEN
strEmailBodyFormattedstr := 'Batch process initialization failed on '+ FORMAT(TODAY) +' !';
SMTPCU.CreateMessage('Sender and recepient details, TRUE);
SMTPCU.Send();