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 03:08 AM
try
var d = new GlideDate();d.setValue(current.u_start_day.getDisplayValue()); d.addDays(182); d.getDisplayValue()
I had more issues with GlideDate and GlideDateTime when I wanted to set the date/time component on calling the class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 04:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 05:17 AM
So, you are wanting to add 182 days to Start Date to create Expiration Date?
If so, then this should do the trick:
var d = new GlideDate(current.u_start_day);
d.addDaysLocalTime(182);
current.u_expiration_date = d.getValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 05:24 AM
Hi Tomer ,
Try below script in business rule
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var gdt = gs.now();
if(your condition){
var gdt = new GlideDateTime();
gdt.addDaysLocalTime(number of days you want to add);
current.your second field name= gdt;
}
}
Mark as correct if it is helpful
Thanks ,
Sumanth