You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ActivityAction =74-- Change Assigned Role From Old -> New
56
-
UNION
60
+
ActivityAction =74-- Change Assigned Role
61
+
),
62
+
PaddedParticipatingRoles(TicketObjectId, ValidFrom, RoleId) AS (
63
+
/*
64
+
3. PAD ROLE HISTORY
65
+
Adds a fallback entry for tickets that never had their role changed and no creation journal exists.
66
+
Uses the Ticket's RecipientRole as the initial role assignment date.
67
+
*/
57
68
SELECT
58
69
[Expression-ObjectID],
59
-
COALESCE(ClosedDate, GETDATE()),
60
-
RecipientRole
70
+
COALESCE(
71
+
MAX(ParticipatingRoles.ValidFrom),
72
+
Ticket.CreatedDate
73
+
),
74
+
Ticket.RecipientRole
61
75
FROM
62
-
SPSActivityClassBase
76
+
ParticipatingRoles
77
+
INNER JOIN SPSActivityClassBase AS Ticket ONParticipatingRoles.TicketObjectId= Ticket.[Expression-ObjectID]
63
78
WHERE
64
-
RecipientRole IS NOT NULL
79
+
Ticket.RecipientRoleIS NOT NULL
80
+
GROUP BY
81
+
[Expression-ObjectID],
82
+
Ticket.CreatedDate,
83
+
Ticket.RecipientRole
65
84
),
66
85
RankedParticipatingRoles(TicketObjectId, RoleId, RoleAssignmentRank) AS (
67
-
/* 3. RANKED ROLE ASSIGNMENTS
86
+
/*
87
+
4. RANKED ROLE ASSIGNMENTS
68
88
Assigns a rank to each Role assignment per Ticket based on the ValidFrom date.
69
89
This allows identifying the first assigned Role and any subsequent Role changes.
70
90
*/
71
91
SELECT
72
92
TicketObjectId,
73
-
RoleId,
93
+
ParticipatingRoles.RoleId,
74
94
ROW_NUMBER() OVER (
75
95
PARTITION BY TicketObjectId
76
96
ORDER BY
77
97
ValidFrom ASC
78
98
) AS RoleAssignmentRank
79
99
FROM
80
100
ParticipatingRoles
101
+
LEFT OUTER JOIN FirstLevelSupportTeams ONParticipatingRoles.RoleId=FirstLevelSupportTeams.RoleId
81
102
WHERE
82
-
RoleId IS NOT NULL-- this ASSUMES that for activity=18 (mail) a dispatch to a role happens BEFORE any work is performed!
103
+
/*
104
+
We have the problem, that sometimes we have no knowledge about the initial role assigned to a ticket (NULL) or a default role (interpreted as Dispatcher) is assigned.
105
+
We want to ignore these roles when determining if a ticket started in First-Level-Support or was escalated.
106
+
*/
107
+
ParticipatingRoles.RoleIdIS NOT NULL
108
+
AND (
109
+
FirstLevelSupportTeams.RoleIdIS NOT NULL
110
+
ORParticipatingRoles.RoleId NOT IN (
111
+
SELECT
112
+
DefaultResponsibleRoleTickets
113
+
FROM
114
+
SPSGlobalConfigurationClassServiceDesk
115
+
UNION
116
+
SELECT
117
+
DefaultResponsibleRoleIncidents
118
+
FROM
119
+
SPSGlobalConfigurationClassServiceDesk
120
+
UNION
121
+
SELECT
122
+
DefaultResponsibleRoleServiceRequests
123
+
FROM
124
+
SPSGlobalConfigurationClassServiceDesk
125
+
)
126
+
)
83
127
),
128
+
TicketStatistics AS (
129
+
/*
130
+
5. AGGREGATION
131
+
Determine FLS status and Escalation status before joining back to main ticket data.
132
+
*/
133
+
SELECT
134
+
RankedParticipatingRoles.TicketObjectId,
135
+
/*
136
+
A ticket was created for First-Level-Support if:
137
+
- the first "relevant" role assigned to the ticket is a First-Level-Support role
138
+
*/
139
+
MAX(
140
+
CASE
141
+
WHEN RankedParticipatingRoles.RoleAssignmentRank=1
142
+
ANDFirstLevelSupportTeams.RoleIdIS NOT NULL THEN 1
143
+
ELSE 0
144
+
END
145
+
) AS StartedInFLS,
146
+
-- Check if ANY role assigned in the history was NOT a First-Level-Support role
147
+
MAX(
148
+
CASE
149
+
WHEN FirstLevelSupportTeams.RoleId IS NULL THEN 1
150
+
ELSE 0
151
+
END
152
+
) AS HasNonFLSHistory
153
+
FROM
154
+
RankedParticipatingRoles
155
+
LEFT JOIN FirstLevelSupportTeams ONRankedParticipatingRoles.RoleId=FirstLevelSupportTeams.RoleId
156
+
GROUP BY
157
+
RankedParticipatingRoles.TicketObjectId
158
+
)
159
+
/*
160
+
* 6. Final Output
161
+
*/
84
162
SELECT
85
-
ticket.ID,
163
+
Ticket.ID,
86
164
CASE
87
-
WHEN ticketCommon.State=204 THEN 1
165
+
WHEN TicketCommon.State=204 THEN 1
88
166
ELSE 0
89
167
END AS IsClosed,
90
-
/*
91
-
A ticket was created for First-Level-Support if:
92
-
- the first "relevant" role assigned to the ticket is a First-Level-Support role
93
-
*/
94
-
/*
95
-
A ticket was closed without escalation if:
96
-
- the ticket is in "Closed" status AND
97
-
- there are NO non-First-Level-Support role assignments in the ticket history
98
-
- the first "relevant" role assigned to the ticket is a First-Level-Support role
99
-
*/
100
-
/*
101
-
A ticket was escalated if:
102
-
- there is at least one non-First-Level-Support role assignment in the ticket history
103
-
- the first "relevant" role assigned to the ticket is a First-Level-Support role
-- Metric 2: Resolved in First-Level-Support (No Escalation)
171
+
CASE
172
+
WHEN Stats.StartedInFLS=1
173
+
ANDStats.HasNonFLSHistory=0
174
+
ANDTicketCommon.State=204 THEN 1
175
+
ELSE 0
176
+
END AS IsFirstLevelSupportResolution,
177
+
-- Metric 3: Escalated from First-Level-Support
178
+
CASE
179
+
WHEN Stats.StartedInFLS=1
180
+
ANDStats.HasNonFLSHistory=1 THEN 1
181
+
ELSE 0
182
+
END AS IsEscalated
105
183
FROM
106
184
dbo.SPSActivityClassBaseAS Ticket
107
185
INNER JOIN (
@@ -110,16 +188,12 @@ FROM
110
188
State
111
189
FROM
112
190
dbo.SPSCommonClassBase
113
-
) AS TicketCommon ON Ticket.[Expression-ObjectID] = TicketCommon.[Expression-ObjectID] --Join with a minimal set of common properties
114
-
INNER JOIN RankedParticipatingRoles ON Ticket.[Expression-ObjectID] =RankedParticipatingRoles.TicketObjectId-- Join with Participating Users to find ~all users involved with the ticket
115
-
LEFT OUTER JOIN FirstLevelSupportTeams ONParticipatingRoles.RoleId=FirstLevelSupportTeams.RoleId
191
+
) AS TicketCommon ON Ticket.[Expression-ObjectID] = TicketCommon.[Expression-ObjectID]
192
+
INNER JOIN TicketStatistics AS Stats ON Ticket.[Expression-ObjectID] =Stats.TicketObjectId
116
193
WHERE
117
194
Ticket.CreatedDate>= DATEADD(year, -3, GETDATE()) -- 3 year sliding window
118
195
AND (
119
196
Ticket.UsedInTypeSPSActivityTypeTicketIS NOT NULL
120
197
ORTicket.UsedInTypeSPSActivityTypeIncidentIS NOT NULL
121
198
ORTicket.UsedInTypeSPSActivityTypeServiceRequestIS NOT NULL
0 commit comments