- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 07:12 AM
Hi,
I am having string type of fields which is calculating the difference between 2 date fields and storing into a string type of field.. So, the value appears in the format of days, hours, minutes, seconds.
(ex: 2 days, 10 hour, 45 minutes, 20 seconds)
But for reporting purpose it is not feasible to calculate .Hence , we want to convert into numeric value(minutes/seconds), etc to calculate properly.
(Ex: 6000) .
So, in excel once report extracted will not face any issue.
Please guide me here, how to get that
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 12:35 AM
Hi,
try this
(function executeRule(current, previous /*null when async*/ ) {
//To display duration between RITM created time and RITM closed time
var start = new GlideDateTime(current.opened_at); //opened time
var end = new GlideDateTime(current.closed_at); //closed time
var dc = new DurationCalculator();
var sch = gs.getProperty('BusinessHoursSchedule');
dc.setSchedule(sch);
var time = dc.calcScheduleDuration(start, end);
var durationMS = time * 1000;
current.u_lifecycle_duration.setDateNumericValue(durationMS);
})(current, previous);
Regards
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
‎09-01-2022 08:21 AM
Hi,
that string field will be storing in this format -> 2 days, 10 hour, 45 minutes, 20 seconds
Why not use Duration field to hold the difference?
If not then you need one extra field which holds the duration possibly in seconds or milliseconds for reporting.
Regards
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
‎09-01-2022 04:56 PM
Hi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 12:10 AM
Hi,
share complete script.
You can find difference between 2 dates and get the numeric value and store in duration field
Regards
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
‎09-02-2022 12:19 AM
Hi
Please find below script
(function executeRule(current, previous /*null when async*/ ) {
//To display duration between RITM created time and RITM closed time
var start = new GlideDateTime(current.opened_at); //opened time
var end = new GlideDateTime(current.closed_at); //closed time
var dc = new DurationCalculator();
var sch = gs.getProperty('BusinessHoursSchedule');
dc.setSchedule(sch);
var time = dc.calcScheduleDuration(start, end);
var durationMS = time * 1000;
var result = new GlideDuration(durationMS);
var duration = result.getDisplayValue();
current.setValue('u_lifecycle_duration', duration);
})(current, previous);