To handle replies to cases that have been locked and closed(our system is set to lock cases after 15 days).
We found that users were responding to old cases, in some instances the employee previously assigned to the case was no longer with the company. The message would get attached to the old case, but no one was aware.
I created the following script that is attached to the Message Record.
The script creates a New case and assigns it to the tech support queue.
function messageAfterSubmit(type)
{
//************************************************** ******************************
//************************************************** ******************************
// This script is run when new messages are sent into NetSuite
//Purpose: To Capture messages sent into closed and locked cases
//Outcome: A new cases will be created and assigned to Tech Support
//
//New cases are created only if the following criteria are met:
// 1. The case is for the our Subsidiary(internal ID: 1)
// 2. The case has a status of Closed(id 5) or Closed on First Contact(7)
// 3. The case has been closed for more than 15 days(Locked by the system)
//
//************************************************** ******************************
//************************************************** ******************************
var record = nlapiGetNewRecord();
var recordId = record.getFieldValue('activity');
var isCase = false;
if (recordId != null && recordId != '')
{
// Do a case search and determine if the id is indeed of a case
var filters = new Array();
var search = nlapiSearchRecord('supportcase', null, filters, null);
if (search != null && search != '')
{
isCase = true;
}
if (isCase)
{
var subsidiary=nlapiLookupField('supportcase',recordId ,'subsidiary');
//Check the subsidiary, 1 is the subsidiary for our subsidiary, this script will only run for our cases
if(subsidiary=='1'){
var originalcasenum=nlapiLookupField('supportcase',rec ordId,'casenumber');
var initMessage=record.getFieldValue('subject');
var currentStatus = nlapiLookupField('supportcase',recordId,'status');
var testuser=nlapiLookupField('supportcase',recordId,' casenumber');
//Check to see that the cases is closed
if(currentStatus=='5'||currentStatus=='7'){ //5 is the
internal id for closed, 7 is the internal id for closed on first contact
//Check for to see if the case has been closed for x days
// Get the Current Time
//************************************************** ****************************
//**********************Date and Time Functions*********************************
//************************************************** ****************************
// Get the current date
var currentDate = new Date()
var month = currentDate.getMonth()
var day = currentDate.getDate()
var year = currentDate.getFullYear()
var caseStatus="";
actualDate=month + "/" + day + "/" + year;
// Get the Current Time
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var ampm="";
if (minutes < 10){
minutes = "0" + minutes
}
if(hours > 11){
ampm="pm";
} else {
ampm="am";
}
DateActual = new Date(year,month,day,hours,minutes,0);
actualTime=hours + ":" + minutes + " "+ampm;
var sDate = new Date(Date.parse(DateActual,"MM/dd/yyyy hh:mm:ss"));
// Get the Closed Date
var EndDate = nlapiLookupField('supportcase',recordId,'enddate') ;
var closedDate= new Date(Date.parse(EndDate,"MM/dd/yyyy hh:mm:ss"));
var timediff=sDate-closedDate;
timediff=((timediff/1000/60)/60)/24; // difference in
days between closed date and now divided by 1000 , divided by seconds,
minutes, hours
//************************************************** ****************************
//****************** End Date Functions ****************************************
//************************************************** ****************************
// Check to see that the cases is at least 15 days old(locked)
if(timediff>15){
var newMSG=initMessage+' - RESPONSE TO LOCKED CASE #'+originalcasenum;
var sCase = nlapiCopyRecord('supportcase', recordId); //Copy the original case record
sCase.setFieldValue('title', newMSG);
sCase.setFieldValue('status', 1); //Internal ID for status 'Not Started'
sCase.setFieldValue('assigned',77115); //Internal id of the Technical Support Group
// Blank out fields
sCase.setFieldValue('custevent_tc_case_scheduled_c allback','');
sCase.setFieldValue('custevent_tc_scheduled_callba ck_time','');
sCase.setFieldValue('custevent_tc_case_assigned',' ');
//Mapping Fields
sCase.setFieldValue('custevent_tc_init_response',' ');
sCase.setFieldValue('custevent_tc_initial_close',' ');
sCase.setFieldValue('custevent_hoursonhold','');
sCase.setFieldValue('custevent_mapping_submitted_b y','');
sCase.setFieldValue('custeventonhold','');
sCase.setFieldValue('custeventeventonholdtime','') ;
sCase.setFieldValue('custeventrestarted','');
sCase.setFieldValue('custeventrestartedtime','');
//Submit the new record to NetSuite
id = nlapiSubmitRecord(sCase, true);
//************************************************** ***************************
//************************* Email the Customer ******************************
//************************************************** ***************************
// var initEmail=record.getFieldValue('author');
// var outSubject=newMSG;
// var outBody=newMSG;
// nlapiLogExecution('Debug', 'Sender = ', initEmail);
// nlapiSendEmail(7, initEmail, outSubject, outBody);
}
}
}
}
}
}