
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2022 12:36 AM
Hello all,
I have a custom application, extended "task" table.
i need to get the task duration, like from record created to closed, taken how many day.
Refer to table below, there time data is all empty, how to make this available?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2022 12:46 AM
You can use metric definition on your custom table, You can refer to the OOTB Incident metric definition in the metric_definition table and modify the script accordingly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2022 12:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2022 02:48 AM
Now trying to create report on this .
Is there a way to get business duration (excluded sat & sun) ?
Please share with me, appreciated.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2022 02:58 AM
You have to use schedule to calculate duration between days excluding holidays and weekends
var dc = new DurationCalculator(); dc.setSchedule('eb65c2250fc76340e1f30dbce1050ee2', 'Los Angeles'); // Schedule sys_id and system time zone
var dur = dc.calcScheduleDuration(start, end); //start - your start date field and end - your end date field
var business_days = dur/(60*60*9);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2022 12:49 AM
Hi,
refer this OOB business rule and create same on your custom table
you would require Duration field type on your table
BR Name: mark_closed
Script: enhance as per your requirement.
setClosureFields();
function setClosureFields() {
// incident_state is Closed so
// 1. mark the task as inactive
// 2. set the closed by to current user if not supplied
// 3. set the closed time to now if not supplied
current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil())
current.closed_at = gs.nowDateTime();
// Update the fields that indicate the time/duration of the incident from open to close.
// Keep track of duration as a glide_duration value (dd hh:mm:ss) and as a pure number of seconds.
// Both calendar time and business time are maintained.
var dataChange = current.opened_at.changes() || (current.closed_at.changes() && !current.isValidField("resolved_at"));
var opened = current.opened_at.getDisplayValue();
var closed = current.closed_at.getDisplayValue();
if (dataChange || current.business_duration.nil())
current.business_duration = gs.calDateDiff(opened, closed, false);
if (dataChange || current.business_stc.nil())
current.business_stc = gs.calDateDiff(opened, closed, true);
if (dataChange || current.calendar_duration.nil())
current.calendar_duration = gs.dateDiff(opened, closed, false);
if (dataChange || current.calendar_stc.nil())
current.calendar_stc = gs.dateDiff(opened, closed, true);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader