Adding days to date field based on another date field (Default value)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 02:05 AM
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:14 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2019 02:19 AM
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
}