I set up a scheduled script to run at midnight every day to find all cases that have a status still identified as 'New' and a custom field 'custevent_respondbyhrs' greater than 0 (respondbyhrs contains the number of raw hours to first response (taking into consideration business hours response versus 24x7 response, holidays, etc)
The function csiWriteToErrorLog simply writes out the error to the execution log using the 'ERROR' classifier which includes the line number of the error for debug purposes. Interestingly this ends up writing out to the execution log as 'DEBUG' which not sure why (could be my function, but I don't see a problem with it). The function _FunctionResults simply writes out to the execution log using the 'AUDIT' classifier that the function finished and shows an error count if errors occurred.
Below is the execution log:
I think Error [line 0] undefined: undefined is supposed to be my AUDIT, script finished, but my code was flawed so ignore (I've fixed since). However Error [line 94] relates to the nlapiSearchRecord function (in red). Hoping someone can shed some light on what may be going wrong.
Execution Log Results:
Debug Error [line 0] undefined: undefined 14-Sep-2006 12:06 am
Debug Error [line 94] null 14-Sep-2006 12:06 am
System Status set by System to SCHEDULED 14-Sep-2006 12:06 am
System Status set by System to INPROGRESS 14-Sep-2006 12:06 am
System Status set by System to INQUEUE 14-Sep-2006 12:03 am
Debug Error [line 0] undefined: undefined 13-Sep-2006 12:06 am
System Status set by System to SCHEDULED 13-Sep-2006 12:06 am
Debug Error [line 94] null 13-Sep-2006 12:06 am
System Status set by System to INPROGRESS 13-Sep-2006 12:06 am
System Status set by System to INQUEUE 13-Sep-2006 12:03 am
Debug Error [line 0] undefined: undefined 12-Sep-2006 12:06 am
Debug Error [line 94] null 12-Sep-2006 12:06 am
System Status set by System to SCHEDULED 12-Sep-2006 12:06 am
System Status set by System to INPROGRESS 12-Sep-2006 12:06 am
System Status set by System to INQUEUE 12-Sep-2006 12:04 am
function _bnnCaseRespondBySearch() {
// set filter to search only for custevent_respondbydate, creationdate and lastmodifieddate
var record;
var errorCnt = 0;
var curHrs = 0;
var results;
var times = new Array();
var filters = new Array();
try {
filters[0] = new nlobjSearchFilter(fRespondByHrs, null, 'greaterthan', 0, null);
filters[1] = new nlobjSearchFilter(fCaseStatus, null, 'equalto', 'New', null );
// filters[2] = new nlobjSearchFilter(fCaseRelatedTo, null, 'startswith', '1-', null );
// filters[3] = new nlobjSearchFilter(fCaseType, null, 'equalto', '2', null );
} catch(e) {
errorCnt += 1;
csiWriteToErrorLog('ERROR', e, 84);
_FunctionResults(errorCnt);
return;
}
try {
results = nlapiSearchRecord(rSupportCase, null, filters, null);
} catch(e) {
errorCnt += 1;
csiWriteToErrorLog('ERROR', e, 94);
results = null;
}
if ( results != null ) {
//times = _bnnGetBusStartEndTimes();
for (var i = 0; i < results.length; i++ ) {
// make sure the record has not already been escalated
if ( results[i].getValue(fEscalatee) == null ) {
// update the respond by hrs by 24 hours less than current
curHrs = parseInt(results[i].getValue(fRespondByHrs));
if ( curHrs > 24 ) { curHrs -= 24; }
if ( curHrs < 0 ) { curHrs = 0; }
// set the cur hrs in the record
// 1. load the record to update
record = nlapiLoadRecord(results[i].getRecordType(),results[i].getId());
// 2. change cur hours to new reading
record.setFieldValue(fRespondByHrs,curHrs);
// 3. save record - [false = not sourcing any fields in record]
try {
var recId = nlapiSubmitRecord(record,false);
if ( recId != results[i].getId() ) {
// an error occurred, get error and notify
var err = new Error(recID);
csiWriteToErrorLog('ERROR', err, 116);
errorCnt += 1;
}
} catch(e) {
errorCnt += 1;
csiWriteToErrorLog('ERROR',e,117);
}
}
}
}
// show that script ran by placing an audit line in script execution log
_FunctionResults(errorCnt);
}