business duration calculation through background script

harshinielath
Tera Expert

We have old incidents with business duration values 'zero'. So I wrote a background script to update values. In our business scenario we need to calculate the business duration as time between opened_at and resolved_at instead of closed_at. The problem is it gives same zero values if calculated between opened_at and resolved_at and gives correct values with closed_at.I don't understand this issue.?Anyone has any thoughts.

This is the background script

var result = 0, count = 0, opened, resolved;

var gr = new GlideRecord( 'incident' );

gr.addQuery("business_duration" , "CONTAINS", '1970-01-01 00:00:00' );

gr.addQuery('opened_at', '>=', '2015-04-02 00:00:00');

gr.addQuery('opened_at', '<=', '2015-05-31 23:59:59');

gr.query();

while(gr.next()) {

opened = gr.opened_at;

resolved= gr.resolved_at;

count++;

result = gs.calDateDiff(opened, resolved, false);

gs.print(gr.number + " " + result);

gr.business_duration=result;

gr.setWorkflow(false);

//gr.update();

}

gs.print("Total records : " + count);

1 ACCEPTED SOLUTION

Harshini take a look at the resolved and closed dates for INC***572, Closed_at is more than 24hrs or 1day. That is why it is returning the value. Look at INC**571 it still returns 0 for both resolved and closed



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

10 REPLIES 10

Though it displays the values only it is more than 24hours in the script output, It calculates correctly and displays in the incident fields.I tried in my demo instance


See this


c2.PNG