
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 03:52 PM
I have a field called "Original Expected Completion Date" that is populated automatically when another field called "Expected Completion Date" is filled in by a user. I need to capture the number of days it took to populate the field by comparing the "Created" date field with the "Updated" date field. I already have a business rule script running on the "Expected Completion Date" field as well.
Any thoughts of how I could accomplish this, example scripts would be great.
Thanks,
Edwin
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2016 10:41 PM
My bad. Here you go. This is how you set a duration field.
Script:
var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var gdt2 = new GlideDateTime(gs.nowDateTime());
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
var dur1= new GlideDuration();
dur1.setValue(dur.getValue());
current.<name of duration field>=dur1.getDurationValue();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2016 09:40 PM
Should there be two "dur" variables? It's throwing an duplicate error
Haven't got it to work so far, but also how do I set the answer to a string field or duration field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2016 10:41 PM
My bad. Here you go. This is how you set a duration field.
Script:
var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var gdt2 = new GlideDateTime(gs.nowDateTime());
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
var dur1= new GlideDuration();
dur1.setValue(dur.getValue());
current.<name of duration field>=dur1.getDurationValue();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2016 08:58 AM
Thank you.... Thank you as always, It worked perfectly!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2016 10:33 PM
I need to modify the script and replace "sys_updated" with "Client Notification Date".
"Client Notification Date is a date fled by the way. The issue it that the calculations are incorrect possible because the sys_created field is a date/time field?
(function executeRule(current, previous /*null when async*/) {
var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var gdt2 = new GlideDate(current.client_notification_date.getDisplayValue());
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
var dur1 = new GlideDuration();
dur1.setValue(dur.getValue());
current.mbo_duration = dur1.getDurationValue();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2020 12:02 PM
Is this a script include, client script or a business rule?