I set up a ServerScript to run before a case record loads (bnnBeforeLoad() function).
Strangely, it only errors when I try to create a case from the Administrator role. Everyone else who has access to create a case does not experience this nor do they generate any errors in the error log for the script. I am also the owner of the script.
I get the following error:
Date & Time: 9/7/2006 5:02 pm
Record Type: Case
Internal ID:
Script: bnnBeforeLoadCase
Error: UNEXPECTED_ERROR
Stack Trace:
#bnnBeforeLoadCase.nlapiSearchRecord(customrecord12, null, [Lcom.netledger.app.common.scripting.nlobjSearchFilter;@a6766b4, [Lcom.netledger.app.common.scripting.nlobjSearchColumn;@a6766cb)
#bnnBeforeLoadCase
And here is the code. Looks like it is bombing on SearchRecord. Basically the code is looking up a holiday record and identifying all listed company holidays from the current date on. It then creates a string of holiday dates which
javascript in the case form uses to populate a holidays array which is used
in calculating when the next business day is for cases that have a next business day response. For example if a case is opened on Friday and Monday is a company holiday, the case sets a field to identify Tues as the next business day to respond by.
/* globals */
var fHolidayClosedDate = "custrecord_business_closed_date";
var fHolidayDateString = "custevent_holidaydatestring";
/* - record names */
/* the specific custom record I'm interested in */
var rHolidays = 'customrecord12';
function bnnBeforeLoadCase(type) {
type = type.toLowerCase();
_bnnGetHolidays(type);
}
function _bnnGetHolidays(type) {
var dateStr = "";
var filters = new Array();
var columns = new Array();
var t = csiGetESTTime(); // custom method; used elsewhere and works
var today = "1/1/2006";
if ( t != null ) {
today = ""+(t.getMonth()+1)+"/"+t.getDate()+"/"+t.getFullYear();
}
filters[0] = new nlobjSearchFilter(fHolidayClosedDate, null, 'onorafter', today, null);
columns[0] = new nlobjSearchColumn(fHolidayClosedDate);
// get the record being loaded
var record = nlapiGetNewRecord();
var results = nlapiSearchRecord(rHolidays, null, filters, columns);
if ( results != null ) {
for (var i = 0; i < results.length; i++ ) {
dateStr += (dateStr==""?"":"|")+results[i].getValue(fHolidayClosedDate);
}
}
// set custom field
record.setFieldValue(fHolidayDateString,dateStr);
}
Thanks.
-Steve