Skip to main content
Book your demo
Example scripts
To homepage
Jira
Data centre icon
Data Center

Add a JQL Filter to a Structure

Created 2 year(s) ago, Updated 2 month(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (7.7 - 8.6)
compatibility bullet
ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.forest.action.ForestAction
import com.almworks.jira.structure.api.generator.CoreGeneratorParameters
import com.almworks.jira.structure.api.generator.CoreStructureGenerators
import com.almworks.jira.structure.api.item.CoreIdentities
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureComponents structureComponents

def structureManager = structureComponents.structureManager
def forestService = structureComponents.forestService
def generatorManager = structureComponents.generatorManager

// Name of the structure you want to add this generator to
final structureName = 'YOUR_STRUCTURE_NAME'

// Get the structure: the false flag is optional, it indicates whether we want to search archived structures or not
def structures = structureManager.getStructuresByName(structureName, PermissionLevel.ADMIN, false)
assert !structures.empty : "No structure found with the name ${structureName}"

def structureId = structures.first().id

// JQL text query of the generator to filter the issues by
final jql = "assignee = admin"

// Build the JQL filter generator generator
def jqlParams = [(CoreGeneratorParameters.JQL): jql] as Map
def jqlFilterId = generatorManager.createGenerator(CoreStructureGenerators.FILTER_JQL, jqlParams, structureId)

// Create the item to add to the structure forest
def generatorItem = CoreIdentities.generator(jqlFilterId)
def forestSource = forestService.getForestSource(ForestSpec.structure(structureId))
forestSource.apply(new ForestAction.Add(generatorItem, 0, 0, 0))
Having an issue with this script?
Report it here