Calculate the duration of each assignment group spent for each state in an incident in PA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 03:27 AM - edited 11-23-2023 03:34 AM
Hi Team,
I would like to know is there any way to calculate the duration of each assignment group spent for each state in an incident in Performance analytics.
eg: INC12345 is in 'work in progress' state and three assignment group worked in this state, such as group A, group B, group C. How to calculate the duration for each group spent under Work in Progress state in PA . Breakdown matrix and breakdown relationship work for this?.
Please share your thought on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 04:18 AM
HI @Vinay T K ,
I trust you are doing great.
If i uderstood the query right the below code will be helpful.
var incidentSysId = 'sys_id_of_incident'; // Replace with your incident sys_id
var state = 'state_code'; // Replace with your state code
var durationByGroup = {};
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', incidentSysId);
gr.query();
if (gr.next()) {
var history = new GlideRecord('sys_history_line');
history.addQuery('field', 'state');
history.addQuery('new', state);
history.addQuery('parent', incidentSysId);
history.orderBy('update_time');
history.query();
var startTime;
var endTime;
var currentGroup;
while (history.next()) {
if (history.getValue('new') == state) {
startTime = history.update_time;
currentGroup = gr.assignment_group;
} else if (history.getValue('old') == state) {
endTime = history.update_time;
if (currentGroup) {
var duration = gs.dateDiff(startTime, endTime, true);
durationByGroup[currentGroup.getDisplayValue()] = (durationByGroup[currentGroup.getDisplayValue()] || 0) + duration;
}
}
}
}
// Output duration by group
for (var group in durationByGroup) {
gs.info('Group: ' + group + ', Duration: ' + durationByGroup[group] + ' seconds');
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 04:41 AM
Hi @Amit Gujarathi ,
Thanks for your reply, But I am mainly looking this for reporting purpose in the performance analytics. I have already created the database view connecting metric table with incident table, and created indicators for incident state with breakdown incident state and incident assignment group. But it is not showing specific duration respected to the assignment group in each state. Breakdown matrix will work for this case?
Regards,
Vinay T K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 04:55 AM
Hi @Vinay T K ,
As to my best knowledge, there is no possibility OOTB from performance analytics, as it is two different values that you would like to monitor (state and assignment group). As far as I see it, you need some sort of scripting / custom development to obtain the information.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 05:12 AM
Hi @AndersBGS
Thanks for your reply, Yes I could not find anything in OOTB. Could you please guide me where can be do the scripting in PA for achieving this requirement.
Regards,
Vinay T K
