SQL query to find the user that resolved/completed the work item
Hello everyone,
I'm trying to write an SQL query to get the user that resolved/completed a work item. (IR and SR)
I've looked around and saw some tips that ServiceManager.dbo.MT_System$WorkItem$Incident_Log contains the records of when the status changed from $notResolved/$notCompleted to $resolved/$completed and then somehow link that EntityChangeLogId to the user who made the change.
But it's that last part that I am struggling with. Does anyone have an SQL example of this? Or perhaps someone could point me in the right direction.
To summarize: I want to have a column that gives me the name of the agent that solved that particular WorkItem, be it SR or IR. So we have to look for when the WorkItem changed to Completed or Resolved and who made that change.
My knowledge of SQL is basic at best so I would really appreciate some help :)!
Answers
This should get you started. It selects all IRs created in the past 7 days
Thanks for the reply!
It did get me on the way!
Is there any way to combine this with both service requests and incidents? My boss wants to see how many total cases are resolved by his agents each week.
My current query looks like this (modified yours a little bit):
@Philip_Håkans
What I did is to create a view that uses an union to merge both IRs and SR's
It is probably some dirty SQL methods, but it works.
Just one question do you have a datawarehouse? If you do it is prefered to use that for reporting.
The only reason why I'm using the live DB is because the managers want real time data and the cireson portal tables does not have my extended classes in.
You can just remove the extended classes for Campus.
I like to use this view because when writing reports, it makes it much easier to reference all the fields I need
Strap on, this is a loooong query :-)
@Philip_Håkans Hey Philip, did you get sorted with this query. Its exactly what my manager needs too!
@David_Johnsen
I'm afraid I never got sorted with this query. I know my way around some basic SQL but I couldn't transform Gerhards query into something that I could present to my manager.
Is the SCSM operational DB your only choice? Or is the SCSM DW or Cireson Analytics on the table?
Operational or Cireson Analytics (we don't have a DW), if the data can be retrieved from these it does not matter from where. It's been a while since I last attempted this, but I think I remember facing the issue of there not being a "resolved by" relationship to find what agent actually solved the case. Only who was assigned to it when it was closed. But I may be wrong, like I said it's been a while 😊
There actually is another option on the table worth exploring - our Platform's OData tables.
You can retrieve the OData through the Platform's API via Excel or directly query it in your ServiceManagement database. These tables typically start with "cachert*" and if you're syncing Incidents into the platform the Resolved By, plain text no joins required display name, is there.
If you're like to see a preview of it in your respective deployment, just update the following URL:
http://portal.domain.tld/platform/api/Cached_MT_System_WorkItem_Incident
The following Knowledge Article also outlines how to configure Excel OData connections.
Doesn't look like we're syncing MT_System$WorkItem$Incident, but I guess it's just as simple as adding it?
You would be 100% correct in that statement.
I would advise just adding MT_System$WorkItem
This is because that table is a starts with, that way you can get all the other workitem tables in without the extra work :-)
Thanks,
Shane