Example scripts
To homepage
Jira

Insert Issues into a Structure Using a JQL Query
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.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 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'
// This is the JQL query you want the generator to execute
final jql = 'project = test and type = story'
def structures = structureManager.getStructuresByName(structureName, PermissionLevel.ADMIN)
assert !structures.empty : "No structure found with the name ${structureName}"
def structureId = structures.first().id
def params = [(CoreGeneratorParameters.JQL): jql] as Map
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))
Having an issue with this script?
Report it here