
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2019 09:50 PM
Hello,
Need a Business Rule to run the following scenario:
Start date + Months = End date - 1 day
- Start date (Date field), i.e. 12/20/2019
- Months (String field), i.e. 24
- End date (Date field), 12/19/2021
Months may need to be a different field type in order for the script to work. It can be changed.
Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 11:54 AM
Used the information others provided to create a Business Rule.
//Start date
var sdate = current.your_start_date_field_name;
//Months. Must be an integer field type.
var mon = current.getValue('your_term_field_name');
//End date
var edate = new GlideDateTime(sdate);
//Add months and substract day(s)
edate.addMonths(mon);
edate.addDays(-1);
current.your_end_date_field_name = edate;
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2019 10:39 PM
can you add more details about this requirement ?
you can try with below sample code:
var mon = 24;
var sd = new GlideDateTime();
sd.addMonths(mon);
gs.print(sd.getDate());
var edt = new GlideDateTime();
edt.addDays(-1);
gs.print(edt.getDate());
if(sd.getDate() == edt.getDate()){
gs.print('hey if');
}
else{
gs.print('else');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2019 09:45 PM
Months is not a set value.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2019 11:39 PM
how will you get month ? any field there , which will hold month value ? if yes use below line.
var mon = current.getValue('month field');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2019 10:47 PM
Hi,
What is your exact requirement?At what condition you want to add months?
Thanks,
Dhananjay.