Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,367,390
Community Members
 
Community Events
168
Community Groups

Insert structure inside a structure using script runner

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events