- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 11:01 AM
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);
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 01:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 11:44 AM
Hello harshini
Try this:
var result = 0, count = 0, opened, resolved;
var gr = new GlideRecord( 'incident' );
//gr.addQuery("business_duration" , "CONTAINS", '1970-01-01 00:00:00' );// what is this line of code for?
gr.addEncodedQuery("opened_atBETWEENjavascript:gs.dateGenerate('2015-04-02','00:00:00')@javascript:gs.dateGenerate('2015-05-31','23:59:59')");
gr.query();
while(gr.next()) {
opened = gr.opened_at;
resolved = gr.resolved_at;
count++;
//gs.print(gr.number + " " + opened+ " "+ resolved);
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);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 12:17 PM
That line is to filter the records for business duration values of 'zero'.
And it is not the problem in fetching records,as I see it gives the correct number of records but not updating values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 12:25 PM
Can you try to print opened and resolved date of these incidents and gs.print(gr.number + " " + result);(what is this line of code returning??)
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 12:42 PM