- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 07:27 AM
Hello All,
I wrote a before business rule where I need a calculate difference between 2 fields and put the duration value in another field :
field 1 : 'sys_created_on'
field 2 : 'u_resolved_time'
and duration to be copied on 'u_time_to_resolve'
Wrote the below script but it is not working :
var startDate = new GlideDateTime(current.sys_created_on);
var endDate = new GlideDateTime(current.u_resolved_time);
current.u_time_to_resolve = gs.dateDiff(startDate.getDisplayValue(),endDate.getDisplayValue(),true);
Can anybody help to understand the miss here ?
Thanks a lot in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 07:53 AM
Hi Swapnil,
try this script once:
var startDate = new GlideDateTime(current.sys_created_on);
var endDate = new GlideDateTime(current.u_resolved_time);
var diff = gs.dateDiff(startDate.getDisplayValue(),endDate.getDisplayValue(),true); // this would return seconds
current.u_time_to_resolved.setDateNumericValue(diff*1000); // this method accepts milliseconds
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 07:55 AM
Hi Alikutty,
Tried that as well , no luck..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 07:50 AM
Check below useful blog for date field calculations
https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 07:53 AM
Hi Swapnil,
try this script once:
var startDate = new GlideDateTime(current.sys_created_on);
var endDate = new GlideDateTime(current.u_resolved_time);
var diff = gs.dateDiff(startDate.getDisplayValue(),endDate.getDisplayValue(),true); // this would return seconds
current.u_time_to_resolved.setDateNumericValue(diff*1000); // this method accepts milliseconds
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 08:11 AM
Hi Ankur,
Tried it..no luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 12:27 AM
Hi Swapnil,
Can you share screenshot of what error you are receiving?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader