Adding days to date field based on another date field (Default value)

Tomer
Kilo Expert

Hello experts,

I'm writing a short script for adding days to date field value based on another field (Record producer):

javascript:var d = new GlideDate(current.u_start_day.getDisplayValue()); d.addDays(182); d.getDisplayValue();

need to add half an year for starting date.

this piece of code worked without my field:

javascript:var d = new GlideDate(current.u_start_day.getDisplayValue()); d.addDays(182); d.getDisplayValue();

but then it's adding days from today (I need to take it from the date on : 'u_start_day' field).

any suggestions?

Thanks,

Tomer.

6 REPLIES 6

Thank you Sumanth, 

i'm using record producer so functionality needs to be client side.

i'll check how to implement it. 

 

thanks tgain,

 

Tomer.

 

Tomer
Kilo Expert

thanks all,

finally I used client side script (OnChange) and it worked for this requirement:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var date = new Date(g_form.getValue('u_start_day'));
date.setDate(date.getDate() + 183); //add half an year
g_form.setValue('expiration_date', formatDate(date));

function formatDate (date) {
return date.getFullYear() + '-' +
leadingZero(date.getMonth() + 1) + '-' +
leadingZero(date.getDate()) + ' ' +
date.getHours() + ':' +
date.getMinutes() + ':' +
date.getSeconds();
}

function leadingZero (value) {
return ("0" + value).slice(-2);
}
//Type appropriate comment here, and begin script below

}