- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 12:42 AM
Hello all,
On the Change request, whenever the Actual End is populated by the system, then the difference between Actual Start and Actual End has to be auto populated in the Duration field (Which contains Days and Hours).
Note: Duration field backend name: (u_duration)
Can someone tell me how can I do this?
Regards,
Lucky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 09:54 PM
it worked for me with the 1st script I shared
(function executeRule(current, previous) { // Add your code here
var startDate = new GlideDateTime(current.start_date);
var endDate = new GlideDateTime(current.end_date);
current.u_duration = GlideDateTime.subtract(startDate, endDate);
})(current, previous);
BR
Output: I gave 2 hours difference, it populated 2 hours, I gave 2mins difference, it populated 2mins
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 09:54 PM
it worked for me with the 1st script I shared
(function executeRule(current, previous) { // Add your code here
var startDate = new GlideDateTime(current.start_date);
var endDate = new GlideDateTime(current.end_date);
current.u_duration = GlideDateTime.subtract(startDate, endDate);
})(current, previous);
BR
Output: I gave 2 hours difference, it populated 2 hours, I gave 2mins difference, it populated 2mins
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 10:36 PM
@Lucky1 The end date/time should be after the start date/time. In your picture, I can see that the end date is before the start date, which is incorrect. Additionally, the duration field is negative, which is why instead of 00:02:00, you are getting 23:58:00 (reverse).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2025 09:33 AM
Yes SIva,
I am really Sorry not to had an eye on it.
Thanks a lot.
🙂
Regards,
Lucky.