Thursday, February 28, 2019

Assign Task after a certain number of days, excluding Holidays

The sample script allows a customer to automate calculation of date when a certain Task or Case is to be escalated after X number of days, excluding Holidays.

Note: Holidays are implemented as custom record

 

function setTaskDateCreation(){
 
 var daysToAdd=5; //number of days based on use case
 //var dateCreated=nlapiDateToString(new Date());
var dateCreated=nlapiGetFieldValue('trandate');
var dateOfTask;

 for(var i=1; i<=daysToAdd; i++){
 
  dateOfTask=nlapiAddDays(nlapiStringToDate(dateCreated), i);
 var holiday;
holiday= isHoliday(dateOfTask);
 
  if(holiday==true) 
      daysToAdd = daysToAdd + 1;   
 }
 
 return dateOfTask;
 
 }
 
 

function isHoliday(dateToCheck){
var filters= new Array(); 

  filters[0]= new nlobjSearchFilter('custrecord_date', null, 'on', nlapiDateToString(dateToCheck));
 var results=nlapiSearchRecord('customrecord_holidays', null, filters,null);
 if(results!=null){
 return true;
 }
 return false;
 }

No comments:

Post a Comment