Insert issues into a structure using a JQL query (with Structure for Jira by ALM Works)

Use JQL queries to add issues to an existing structure with this JQL insert generator. The script is compatible with Structure for Jira 4.1 +.

Remember: This script requires Structure for Jira by ALM Works.

Requirements

Jira Jira (7.3 - 7.13)

import com.almworks.jira.structure.api.StructureComponents
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.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

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

def structureName = "YOUR_STRUCTURE_NAME" // name of the structure you want to add this generator to
def jql = 'project = test and type = story' // this is the JQL query you want the generator to execute

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

def structures = structureManager.getStructuresByName(structureName, PermissionLevel.ADMIN)
assert !structures.isEmpty() : "No structure found with the name $structureName"

def structureId = structures.first().id

def params = [:] as HashMap
params.put(CoreGeneratorParameters.JQL, jql)
def jqlInserterId = generatorManager.createGenerator(CoreStructureGenerators.INSERTER_JQL, params, structureId)
def generatorItem = CoreIdentities.generator(jqlInserterId) // item to add to forest
def forestSource = forestService.getForestSource(ForestSpec.structure(structureId)) // resolving forest source for structure
forestSource.apply(new ForestAction.Add(generatorItem, 0, 0, 0))
Discovered an issue? Report it here

Suggested for you

Appears in these Collections