- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 09:07 PM
Here is my bus rule script. I want to populate automatically the u_eol_date (date/time field) with the sys_created_on date (date/time field) PLUS the u_years_of_life value (integer).
Notice on the form results below, it works to some degree, though it is short by a day and the time is a bit off. Not a biggie but wondering how to get it right. Also is a bus rule the best way to do it?
Bus Rule Script
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var CreateDate = current.sys_created_on;
var WarYears = current.u_years_of_life;
var gDate = new GlideDate();
gDate.setValue(CreateDate);
var gDT = new GlideDateTime(gDate);
gDT.addYears(WarYears);
current.u_eol_date = gDT.getDate();
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 10:35 PM
Your gDT.getDate() is taking just the date so it's '2014-08-11'. Then the hours are added due to this being a datetime field.
Try using current.u_eol_date = gDT.getValue();
I'd also change the new GlideDate() to new GlideDateTime() on gDate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 10:35 PM
Your gDT.getDate() is taking just the date so it's '2014-08-11'. Then the hours are added due to this being a datetime field.
Try using current.u_eol_date = gDT.getValue();
I'd also change the new GlideDate() to new GlideDateTime() on gDate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2018 07:52 AM
Bingo! That works. Thank Joni!