I want my Planned Start date to select 3 days after from todays date.

harsha48
Mega Contributor

Hi Folks,

 

I have a requirement on change request. For normal change when we select

****Urgency as Normal - Planned start date should allow to select the dates after 3 days from today's date but shouldn't allow to select the past dates.

****Urgency as Expedited (we created this custom choice) - Planned start date can allow any future dates from today's date (This doesn't have 3 days restriction) but shouldn't allow to select the past dates.

 

 

Can someone please guide me the script on this requirement'

 

1 REPLY 1

Syedmd08
Kilo Guru

// get the current date and time
var now = new GlideDateTime();
now.addDays(3); // add 3 days to the current date

// get the urgency and planned start date values
var urgency = current.variables.urgency;
var plannedStartDate = new GlideDateTime(current.variables.planned_start_date);

// if urgency is normal, planned start date should be after 3 days from today's date
if (urgency == 'normal') {
if (plannedStartDate.before(now)) {
current.variables.planned_start_date.setError('Planned start date cannot be before ' + now.getDate() + '/' + (now.getMonth() + 1) + '/' + now.getYear());
}
}

// if urgency is expedited, planned start date can be any future date
if (urgency == 'expedited') {
if (plannedStartDate.before(new GlideDateTime())) {
current.variables.planned_start_date.setError('Planned start date cannot be in the past');
}
}

 

This script first gets the current date and time using the GlideDateTime() function. Then it checks the urgency and planned start date values using current.variables.

If the urgency is normal, it checks if the planned start date is before 3 days from now. If it is, it sets an error message using the setError() function.

If the urgency is expedited, it simply checks if the planned start date is in the past. If it is, it sets an error message using the setError() function.

You can add this script to the onSubmit or onLoad client script of your change request form to implement these requirements.

 

Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!