SCSM SQL - Quickly View Existing Workflow History of an Incident
While the SCSM Console has a top down approach designed by Satan to look for the workflow history of an Incident or any other ticket.
- [SCSM Console] -> [Administration] -> [Workflows] -> [Status]
- Attempt to find the workflow you think failed the ticket or didn't get triggered
- Check both Need attention and All instances Tabs
- Realize you're in Hell because you have to click on each "View Related Object" to find out what ticket the workflow is about around the time from the ticket history logs
But now, C Sharp Conner has a far less tormentful way of going about this.
Wow, really C Sharp Conner?
Wow Really Indeed, my tormented scsm'r, indeed I do!
By painstakingly brute forcing combining tables and columns, I finally created a query that could check on the existing workflow history of a ticket. Now you can very quickly check if a workflow was created for a ticket or not.
The below example uses the Incident Table but you could set it up for SRs or CRs as well if needed.
USE ServiceManager;
SELECT TOP 1000 LT.[LTValue] AS 'Workflow Name' ,
Wflw.[RuleName] AS 'Workflow InternalName' ,
JobDetail.[ErrorCode] JobDetail.[ErrorMessage] ,
JobDetail.[LastModified] ,
JobDetail.[Output] AS 'Workflow Actions Log (XML)' ,
JobDetail.[TimeStarted] ,
JobDetail.[TimeScheduled] ,
JobDetail.[TimeFinished]
FROM [dbo].[WindowsWorkflowTaskJobStatus] WinWorkflow (nolock)
JOIN [dbo].[Rules] Wflw (nolock) ON Wflw.RuleId = WinWorkflow.[RuleId]
JOIN [dbo].[LocalizedText] LT (nolock) ON Wflw.[RuleId] = LT.[MPElementId]
AND LT.LTStringType=1 AND LT.LanguageCode = 'ENU'
JOIN [dbo].[JobStatus] JobDetail (nolock) ON JobDetail.[BatchId] = WinWorkflow.[BatchId]
JOIN [dbo].[MT_System$WorkItem$Incident] IR (nolock) ON WinWorkflow.[BaseManagedEntityId] = IR.[BaseManagedEntityId]
--WHERE WinWorkflow.[BaseManagedEntityId] LIKE 'F2647B28-71D7-486F-FBC0-80B498A8F9D0' WHERE IR.[Id_9A505725_E2F2_447F_271B_9B9F4F0D190C] LIKE 'IR708644'
While this may appear simple, it was a living hell figuring it out without documentation.