My requirement is to pick the error logs for particular batch jobs.
Click on the view tasks to check the execution log details. I need to get the below error details in custom form.
Code :
This code picks the latest executed batch record. you can apply conditions based on the requirement.
BatchJobHistory batchJobHistory;
select batchJobHistory
order by batchJobHistory.RecId desc
where batchJobHistory.BatchJobId == "5638569578";
if(batchJobHistory.Status == BatchStatus::Error)
{
BatchHistory batchHistory;
BatchJobHistory batchJobHistoryloc;
SysInfologEnumerator enumerator;
while select RecId, Info, Caption from batchHistory where
batchHistory.BatchJobHistoryId == batchJobHistory.RecId
&& batchHistory.Status == BatchStatus::Error
{
str ret;
enumerator = SysInfologEnumerator::newData(batchHistory.Info);
while (enumerator.moveNext())
{
if (enumerator.currentException() == Exception::Error)
{
ret += enumerator.currentMessage() + '\n';
}
}
errorBatchJobTable.Log = ret; // holds the error.
}
}
Output :
Note : BatchJobHistory::showlog() method brings the full log for the history. See the message details.
No comments:
Post a Comment