I often find myself clicking through Batch Job Info Logs while troubleshooting issues. Every time I do this I think "wouldn't it be nice if I could just search the logs for a particular string all at once letting the system do all the work instead of my mouse". So I spent some time creating a Job that can do this for me from the AOT and have included the code below. Just alter the 3 parameters and run the job in the AOT. The parameters are the Record Id of the batch job, the search string, and how many days backwards to search. The Record Id of the batch job can be seen by right clicking the batch job and selecting view record. The code could easily be changed to search on the caption. The output is a list of start times in the local time zone for jobs that have the search string in their Info Logs.
static void BCN_SearchBatchHistoryInfo(Args _args)
{
InfologData data;
BatchJobHistory BatchJobHistory;
DateTimeUtil DateTimeUtil;
int i, countItems, jobsProcessed, strsFound, daysBack;
str strSearch, strCurrent;
int64 BatchJobId;
int printInterval = 100;
;
//Input Parameters
strSearch = "22WTA-KW032";
BatchJobId = 5637243629; //Right Click a Batch Job and select Record Info to get this
daysBack=90;
//Start Looking
print(strFmt("Searching for \"%1\"", strSearch));
info(strFmt("Search String = \"%1\"", strSearch));
jobsProcessed = 0;
strsFound = 0;
while select BatchJobHistory
order by BatchJobHistory.createdDateTime
where BatchJobHistory.BatchJobId == BatchJobId &&
BatchJobHistory.createdDateTime > DatetimeUtil::addDays(DatetimeUtil::utcNow(),-daysBack)
{
jobsProcessed++ ;
if (jobsProcessed == 1) info(strFmt("Caption = \"%1\"", BatchJobHistory.caption));
if (batchJobHistory && batchJobHistory.RecId)
{
data = BatchJobHistory::showLog(batchJobHistory.RecId);
countItems = conlen(data);
for(i=1;i<=countItems;i+=3) //Make sure there is a plus after the "i" given the blog editor keeps removing it
{
strCurrent = info::infoCon2Str(conpeek(data, i+2));
if ( strScan(strCurrent, strSearch, 1, strLen(strCurrent) ) )
{
strsFound++ ; //We found the string
print (strFmt("Start Time = %1", DateTimeUtil::applyTimeZoneOffset(BatchJobHistory.StartDateTime, DateTimeUtil::getCompanyTimeZone()) ));
info (strFmt("Start Time = %1", DateTimeUtil::applyTimeZoneOffset(BatchJobHistory.StartDateTime, DateTimeUtil::getCompanyTimeZone()) ));
}
}
} //Print a message every 1000 jobs searched
if (jobsProcessed mod printInterval == 0 ) print(strFmt("Logs Searched = %1 ...", jobsProcessed));
}
print(strFmt("Logs Searched = %1", jobsProcessed));
print("*** Yes to Exit ***");
//pause; //Pause so we see the print statements
info(strFmt("Searched = %1", jobsProcessed, strSearch));
info(strFmt("Found = %1", strsFound));
}