
- 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-26-2016 03:58 PM
Hi Edwin, I could not understand the requirement here. Could you please elaborate.
However you can go through this thread which might help..
https://community.servicenow.com/thread/166041
Thanks
Rahul Kathuria
Please mark the answer correct if this helps***

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 04:02 PM
When should the clock stop in your case? What do you mean by updated field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 04:33 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 04:53 PM
Write a before business rule
when: before insert and update
Conditions: Original Expected Completion Date" changes AND Original Expected Completion Date" is not empty
Script:
var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var gdt2 = new GlideDateTime(gs.nowDateTime());
var dur = new GlideDuration();
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
gs.print(dur.getDisplayValue()); //this will give you the difference in days and hours