
- 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-22-2019 09:43 PM
Requirement
Start date + Months = End date - 1 day
When to run
When: Before
Filter Conditions: Start date changes OR Months changes
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2019 01:18 AM
Hi Chaquino,
I am performing on incident table as you havent mentioned the exact requirement.Change as per your requirement.
var gr=new GlideRecord('incident');
gr.addQuery('number','INC0010213');
gr.query();
while(gr.next())
{
var date1=gr.sys_created_on;
var f = new GlideDateTime(date1);
f.addMonths(24);
f.addDays(-1);
gs.addInfoMessage(f);
}
mark correct/helpful based on impact.
Thanks,
Dhananjay.

- 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);