Here at Isos Technology, we've seen use cases for pretty much everything. One use case that has come up for both my clients and myself as an admin has been identifying which workflows are applied to a specific issue type across the instance.Say you want to deprecate an issue type or do some other form of analysis on its usage. If you go to the analyze the issue types in the admin UI of Jira, it will only show you the related issue type schemes for each issue type, so you can't really gain any useful information on which workflows are applied to the issue type from the UI.
So, in this blog post, I will show you how to quickly identify all workflows applied to an issue type across your Jira instance using a simple Groovy script! To run it, just pull up a Groovy console in Jira (note that a Groovy console comes with some typical apps like JMWE and may not be available out-of-the-box).
Let's jump right in:
As you can see from above, line 8 is the only place you need to edit the script to gather the needed information. Enter the issue type ID for the issue type you're searching for in place of the "1" I currently have in there. What the script does is iterate over all workflow mappings (i.e. workflow schemes, which by definition map workflows to issue types in a project) to see which workflows map to the issue type ID you specify.
One big caveat to this method is that workflow schemes will output a value of "0" when evaluating the default workflow mapping of a workflow scheme. So to capture these, we have a second "if" statement to see if we're dealing with a default workflow. If we are, we still need to check if the workflow is actually associated with the issue type you specify, since the projects using this default workflow may not even use the issue type. Let me run you through an example of this edge case for clarity. I can have a workflow scheme shown below:
If I am searching for all workflows associated with the Change issue type, we would want to detect the CS: JSSD IT Support Workflow (v2) workflow above. As noted, when we iterate over the workflow schemes, the API will return "0" for issue type ID when evaluating this workflow, since it is the default workflow in this workflow scheme (it's not associated with any issue types not specified elsewhere in the workflow scheme mappings). So if all we get from the API is a zero, we know we hit a default mapping but we don't know if the project is actually using the Change issue type! To check this, our code finds all projects using the workflow and makes sure at least one of them is using the Change issue type, in this example.
After our code finds all the workflows utilizing your specified issue type, we remove any duplicates from our list and output it to the console. Here's an example of output from my script above:
And voilà! It's as simple as that! I hope these script snippets can help speed your admin tasks or client needs along. And as always, happy automating!