Example scripts
To homepage
Jira

Show all Structures Corresponding Item Counts
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (7.7 - 8.6)

ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.almworks.jira.structure.api.StructureComponents
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.xml.MarkupBuilder
import org.apache.commons.lang.StringEscapeUtils
@WithPlugin('com.almworks.jira.structure')
@PluginModule
StructureComponents structureComponents
def structureManager = structureComponents.structureManager
def forestService = structureComponents.forestService
// Get all the structures accessible to the current user at the specified permission level
final permissionLevel = PermissionLevel.NONE
def structures = structureManager.getAllStructures(permissionLevel)
// Extract name, id and elements size for each structure, and sort them by size in descending order
def structureSizeInfoList = structures.collect { structure ->
def forestSource = forestService.getForestSource(ForestSpec.skeleton(structure.id))
[nameAndId: "${structure.name} (#${structure.id})", size: forestSource.latest.forest.size()]
}.sort { s1, s2 -> s2.size <=> s1.size }
// Build the HTML table
def writer = new StringWriter()
def markupBuilder = new MarkupBuilder(writer)
markupBuilder.table {
thead {
tr {
th("Structure Name (ID)")
th("Number of manually added rows")
}
}
tbody {
structureSizeInfoList.collect { structure ->
tr {
td(StringEscapeUtils.escapeHtml(structure.nameAndId))
td(structure.size)
}
}
}
}
writer
Having an issue with this script?
Report it here