Populate End Date based on Start Date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:07 AM
Hello Guys,
I need to populate end date based on start date. on the form when we already have start date displayed. but when state changes I want end date to be auto populated with start date + 10days.
Below is the Before BR rule, I am using but no luck.
var sDate = new GlideDateTime(current.start_date);
sDate.addDays(10);
current.end_date= sDate;
Any help is appreciated.
Thanks,
Rocky.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:15 AM
Hi Rocky,
Please try
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var selected_date = new Date(getDateFromFormat(newValue, g_user_date_time_format));
//add 5 days to the selected date.
selected_date.setDate(selected_date.getDate() + 10);
var selected_dateStr = formatDate(selected_date, g_user_date_time_format);
g_form.setValue('work_start',selected_dateStr);
}
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 10:00 AM
This did not work?
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 10:09 AM
Hello Yousaf,
Your code needs little correction g_user_date_format instead of g_user_date_time_format
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var selected_date = new Date(getDateFromFormat(newValue, g_user_date_format));
//add 5 days to the selected date.
selected_date.setDate(selected_date.getDate() + 10);
var selected_dateStr = formatDate(selected_date, g_user_date_format);
g_form.setValue('work_start',selected_dateStr);
}
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 10:20 AM
Hi Mahendra
I don't think this will be a problem. assuming its a date/time field
As rocky also using GlideDateTime().
***Mark Correct or Helpful if it helps.***