Populate End Date based on Start Date

Rocky5
Kilo Sage

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.

11 REPLIES 11

Yousaf
Giga Sage

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.***

@Rocky 

This did not work?


***Mark Correct or Helpful if it helps.***

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

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.***