Blog - Isos Technology

Jira Admin Tip #3: A Groovy Way to Find All Screen Schemes Associated with an Issue Type

Written by Amanda Kirk | Jul 13, 2021

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 screen schemes are associated with 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 screen schemes are associated with the issue type from the UI.

So, in this blog post, I will show you how to quickly identify all screen schemes associated with 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: 

 

import com.atlassian.jira.component.ComponentAccessor
def schemeManager = ComponentAccessor.issueTypeScreenSchemeManager
def sb = new StringBuffer()
 
//replace with your issue type name and issue type id
def issueTypeName = "Client"
def isssueTypeId = "13102"
//will store the found screen schemess
def screenschemesFound = []
 
//iterate over all projects in instance
ComponentAccessor.getProjectManager().getProjectObjects().each{ project->
    //iterate over issue types for this project
    project.getIssueTypes().each{ issuetype->
        def thisIssueTypeName = issuetype.name.toString()
        //check if correct issue type
        if(thisIssueTypeName == issueTypeName) {
          //get issue type screen scheme name for project
          def isss = schemeManager.getIssueTypeScreenScheme(project)
          def isssEntities = isss.getEntities()
          //iterate over issue type screen scheme entities
          def found = false
          isssEntities.each{ entity->
            //if issuetype is used, add to results
            if((entity.getIssueTypeId() == isssueTypeId)){
              def schemeName = entity.getFieldScreenScheme().getName()
              screenschemesFound.add(schemeName)
              found = true
            }
          }
          if (!found){
            //if no screen scheme found for the issue type, it must be the default
            isssEntities.each{ entity->
              if(!entity.getIssueTypeId()){
                def schemeName = entity.getFieldScreenScheme().getName()
                screenschemesFound.add(schemeName)
              }
            }
          }
        }
    }
}
//output unique list of workflows
(screenschemesFound.unique()).each{
  sb.append(it + "\n")
}
return sb.toString()

 

As you can see from the above, lines 6 and 7 are the only places you need to edit the above script to gather the needed information. Enter the issue type ID for the issue type you are searching for, as well as the name. What the script does is iterate over all projects to see which projects use the issue type. Then, for projects that use the issue type we iterate over the issue type screen scheme entities to find which screen schemes map to the issue type. If we find it, great – we add it to the results.

One caveat is that if our issue type is associated with the default screen scheme within the mapping (i.e., the issue type screen scheme), the API will not return the issue ID...it returns null. So if we happen to not find a specific mapping of the screen scheme for your issue type, we run back through to grab the default since, by default (haha, see what I did there), it is the screen scheme that will be used for your issue type.

After our code finds all the screen schemes associated your specified issue type, we remove any duplicates from our list and output it to the console. Here is an example of output from my script above:

 

Screen schemes found: 
Customer Project Default Screen Scheme
Atlassian External Services Screen Scheme
Default Screen Scheme
CLIENT: Screen Scheme

 

And voilà! It is as simple as that! I hope these script snippets can help speed your admin tasks or client needs along. And as always, happy automating!