
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:24 AM - edited 09-25-2023 04:29 AM
Hi,
I have created a custom choice type column on the change_request table called 'u_lead_time_duration'. On that I have defined three choices:
1_day_lead
3_days_lead
5_days_lead
The plan now is that if 1_day_lead is selected, it should not be possible to set a 'Planned start date' (start_date) less than 1 day (or 24 hours) ahead in time. 3_days_lead means not possible to select a 'Planned start date' less than 3 days ahead in time and so forth.
I have then created an onChange Client Script also on the change_request table looking at the field name 'Planned start date'. The script is this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var startDate = g_form.getValue('start_date');
var leadTimeDuration = g_form.getValue('u_lead_time_duration');
if (startDate && leadTimeDuration) {
var minDate = new Date();
minDate.setHours(0, 0, 0, 0); // Set time to midnight
switch (leadTimeDuration) {
case '1_day_lead':
minDate.setDate(minDate.getDate() + 1);
break;
case '3_days_lead':
minDate.setDate(minDate.getDate() + 3);
break;
case '5_days_lead':
minDate.setDate(minDate.getDate() + 5);
break;
}
var selectedDate = new Date(startDate);
if (selectedDate < minDate) {
g_form.addErrorMessage("Start date cannot precede the specified lead time of " + leadTimeDuration + ".");
g_form.clearValue('start_date');
}
}
}
Can you help me make this script work?
Best regards
Thomas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 01:02 AM
Hi @Thomas G
Yes it would be easier. Before that can you please try this client script?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var format = g_user_date_time_format;
var startDate = g_form.getValue('start_date');
var leadTimeDuration = g_form.getValue('u_lead_time_duration');
if (startDate && leadTimeDuration) {
var minDate = new Date();
minDate.setHours(0, 0, 0, 0); // Set time to midnight
switch (leadTimeDuration) {
case '1_day_lead':
minDate.setDate(minDate.getDate() + 1);
break;
case '3_days_lead':
minDate.setDate(minDate.getDate() + 3);
break;
case '5_days_lead':
minDate.setDate(minDate.getDate() + 5);
break;
}
// get date strings into a number of milliseconds since 1970-01-01
var startDateMs = getDateFromFormat(startDate, format);
var leadDateMS = minDate.getTime();
if (startDateMs < leadDateMS) {
g_form.addErrorMessage("Start date cannot precede the specified lead time of " + leadTimeDuration + ".");
g_form.clearValue('start_date');
}
}
}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 02:29 AM
@Thomas G These modifications looks great, I'll save this code snippet for future reference. 😀
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 12:45 AM
In a change_request form, if model is 'Normal' and creation of change request is today, then in this case 'Planned Start Date' should be after 3 business days (weekends must be excluded). If user tries to select time less than 3 days, error should be visible to set any date after 3 days.
Kindly help in achieving this, if you will provide proper script that will be highly appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:57 AM
Hi Anvesh and thanks for your reply,
With your code I get a message saying: 'Invalid date' no matter what start date I choose if a 'Lead time duration' is set, and when I click on OK to that, I get another message saying: 'Tue Sep 26 2023 00:00:00 GMT+0200 (Centraleuropæisk sommertid)'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 05:05 AM
@Thomas G check the choice values once, whether they are matching with the code. And add another alert just before the switch block like the one below.
alert(minDate);
see what the first alert is showing.
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:57 AM
Hi,
Ensure the below values are set as Value on choice options. If values are different then update the script to use those values:
1_day_lead
3_days_lead
5_days_lead
Palani