How do I determine why the Business Resolve Time is 0

robinf_chadwick
Giga Contributor

We are on Instanbul - Patch 9a

We have a number of incidents that are being closed with a Business Resolve Time of 0 and I can't figure out why.

Here's a screen shot showing the incidents and their particulars.

find_real_file.png

2 REPLIES 2

harshinielath
Tera Expert

Hi


We had the same problem after the Istanbul patch9a was made.On contacting the HI community, they could not give reasons behind these and gave a solution of using background script to update the values explicitly for old tickets.Below is the background script.




var result = 0, count = 0, opened, closed;
var gr = new GlideRecord( 'incident' );
gr.addQuery("business_duration" , "CONTAINS", '1970-01-01 00:00:00' );
gr.addQuery("state", '7');
gr.query();
while(gr.next()) {
opened = gr.opened_at;
closed = gr.closed_at;
count++;
result = gs.calDateDiff(opened, closed, false);
gs.print(gr.number + " " + result);
gr.business_duration=result;
gr.setWorkflow(false);
gr.update();
}
gs.print("Total records : " + count);


robinchadwick
Mega Expert

I worked with a HI Analyst to modify the business rule to populate the Business resolve time and the Business duration.  In our case there is a schedule in play.  Only hours during the schedule are calculated in the business values.  You need to update 2 business rules for the Incident table (Mark_Resolved,  Mark_Closed)

THIS IS THE SCRIPT FOR MARK_RESOLVED

setResolutionFields();

function setResolutionFields() {
if (current.resolved_by.nil())
current.resolved_by = gs.getUserID();
if (current.resolved_at.nil())
current.resolved_at = gs.nowDateTime();

// Update the fields that indicate the time and duration of this incident from open to resolve.
// 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.resolved_at.changes();
var opened = current.opened_at.getDisplayValue();
var resolved = current.resolved_at.getDisplayValue();

var busduration = calcDurationSchedule(current.opened_at,current.resolved_at);
var busresolvetime = (busduration.getNumericValue()/1000);

if (dataChange || current.business_duration.nil())
current.business_duration = busduration;

if (dataChange || current.business_stc.nil())
current.business_stc = busresolvetime;

if (dataChange || current.calendar_duration.nil())
current.calendar_duration = gs.dateDiff(opened, resolved, false);

if (dataChange || current.calendar_stc.nil())
current.calendar_stc = gs.dateDiff(opened, resolved, true);


function calcDurationSchedule(start,end) {
// Get the user
var usr =new GlideRecord('sys_user');
usr.get(gs.getUserID());

// Create schedule - pass in the sys_id of your standard work day schedule and pass in the users timezone
var sched = new GlideSchedule('39b6f9982ba7a100575bad1fe8da158d',usr.time_zone);

// Get duration based on schedule/timezone
return(sched.duration(start.getGlideObject(), end.getGlideObject()));

 

THIS IS THE SCRIPT FOR MARK_CLOSED

setClosureFields();

function setClosureFields() {
// 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();

var busClosedDuration = calcDurationSchedule(current.opened_at,current.closed_at);
var busClosedTime = (busClosedDuration.getNumericValue()/1000);

if (dataChange || current.business_duration.nil())
current.business_duration = busClosedDuration;

if (dataChange || current.business_stc.nil())
current.business_stc = busClosedTime;

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);

function calcDurationSchedule(start,end) {
// Get the user
var usr =new GlideRecord('sys_user');
usr.get(gs.getUserID());

// Create schedule - pass in the sys_id of your standard work day schedule and pass in the users timezone
var sched =new GlideSchedule('39b6f9982ba7a100575bad1fe8da158d',usr.time_zone);

// Get duration based on schedule/timezone
return(sched.duration(start.getGlideObject(), end.getGlideObject()));
}
}