Skip to main content
Skip table of contents

Show All Structure Boards and Corresponding Item Counts

This script will show you the list of structures on the instance and the number of items added to each structure manually. These manual items include Generators.

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.almworks.jira.structure.util.Util
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@Grab(group = 'com.almworks.jira.structure', module = 'structure-api', version = '16.9.0')
@WithPlugin('com.almworks.jira.structure')

StructureComponents structureComponents = ComponentAccessor.getOSGiComponentInstanceOfType(StructureComponents)
def structureManager = structureComponents.getStructureManager()
def forestService = structureComponents.getForestService()

def structures = structureManager.getAllStructures(PermissionLevel.NONE)
def map = structures.collectEntries {
  def fs = forestService.getForestSource(ForestSpec.skeleton(it.id))
  [(it.name + ' (#' + it.id + ')'): fs.getLatest().getForest().size()]
}

map = map.sort {-it.value}

'<table><tr><th>Structure Name (ID)</th><th>Number of manually added rows</th></tr>' +
map.collect {'<tr><td>' + Util.htmlEncode(it.key as String) + '</td><td>' + it.value + '</td></tr>'}.join('')  +
  '</table>'

This script can be adopted to show the count of dynamically generated items by replacing ForestSpec.skeleton() with ForestSpec.structure(). However, running this script will trigger all the structures and their generators, which can cause a performance impact. Be careful when running this in a production environment.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.