Sunday, December 9, 2018

Use script to set a date within business days only

Currently, we do not have an API that would identify if a given date is a weekday. However, we may use the script below to workaround the problem. The script sets a custom ship date value to 5 business days from the day the order is created, on before record submit:

function excludeBusinessDays(){
 var daysToAdd=5; //number of days based on use case
 var dateCreated= nlapiGetFieldValue('trandate');
 var dateToShip;

 for(var i=1; i<=daysToAdd; i++){
  dateToShip=nlapiAddDays(nlapiStringToDate(dateCreated), i);

   //if day  is Sunday or Saturday, add another day
  if((dateToShip.getDay()==0)|| (dateToShip.getDay()==6)){  
  daysToAdd = daysToAdd + 1;
 nlapiSetFieldValue('custbody_shipping_date', nlapiDateToString(dateToShip));

No comments:

Post a Comment