Sunday, June 23, 2019

Client Script > Display Message > if expected date is lower than todays date

If via script a message wants to be displayed when the selected date field is less or greater than today's date, please refer to script below which can be deployed as a client script as a field change event:

function xxx(type,name)
{

if (name == 'custrecord54');  // id of the custom date field
 {
 var date = new Date();             // get today's date and get the seconds, hours and minutes
var dt = date.getUTCSeconds();
var hours = date.getUTCHours();
var min = date.getUTCMinutes();

var da = nlapiGetFieldValue('custrecord54'); // get the custom date field value
var da1 = nlapiStringToDate(da);

// set the seconds to be larger than what time new date object has for it to differentiate

da1.setUTCSeconds(dt+1);
da1.setUTCHours(hours);
da1.setUTCMinutes(min);

 if(date > da1)
 {
  alert("xxxxxxxxxxx");
return true; 
}
}
return true;
}

No comments:

Post a Comment