Insert structure inside a structure using script runner

Pavan November 17, 2021

Hello Team,

Thanks in advance.

Normally , Manually I am able to add structure inside structure.
By following below steps

Automation >> + sign >> insert >> Structure >> structure name >> Done

I want to automate this process using scriptrunner

1 answer

1 vote
Stepan Kholodov _ALM Works_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
November 19, 2021

Hello @Pavan 

You can try the script below:

package examples.docs.structure

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
import com.atlassian.jira.component.ComponentAccessor
import com.almworks.jira.structure.api.structure.Structure
import com.almworks.jira.structure.api.forest.action.ForestAction
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.item.CoreIdentities
import com.almworks.jira.structure.api.generator.CoreGeneratorParameters

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

def parentStructureName = "Parent" // name of the structure you want to add this generator to
def innerStructureName = "Inner" // name of the structure to add

def structureManager = structureComponents.getStructureManager()
def forestService = structureComponents.getForestService()
def generatorManager = structureComponents.getGeneratorManager()
def permission = PermissionLevel.valueOf("ADMIN")
def parentStructureId = structureManager.getStructuresByName(parentStructureName, permission)[0].getId()
def innerStructureId = structureManager.getStructuresByName(innerStructureName, permission)[0].getId()

// inserter
def params = ['forestSpec' : ['structureId' : innerStructureId]]
def inserterId = generatorManager.createGenerator("com.almworks.jira.structure:inserter-substructure", params, parentStructureId)
def generatorItem = CoreIdentities.generator(inserterId) // item to add to forest
def forestSource = forestService.getForestSource(ForestSpec.structure(parentStructureId)) //resolving forest source for structure
forestSource.apply(new ForestAction.Add(generatorItem, 0, 0, 0))

I hope this helps. If you need our assistance with anything, please feel free to contact us directly at support.almworks.com and we'll get back to you shortly.

Best regards,
Stepan Kholodov
ALM Works

Pavan December 6, 2021

Thanks ! above solution worked for me 
@Stepan Kholodov _ALM Works_ 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events