Skip to main content
Skip table of contents

Creating a New Structure Programmatically

Running the following script you can create a new structure.

GROOVY
package examples.docs.structure

import com.atlassian.jira.component.ComponentAccessor
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.structure.Structure
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@Grab(group = 'com.almworks.jira.structure', module = 'structure-api', version = '16.9.0')

@WithPlugin("com.almworks.jira.structure")

@PluginModule
StructureComponents structureComponents

def structureManager = structureComponents.getStructureManager()

def permission = PermissionLevel.valueOf("ADMIN")

// It is important to check if an existing structure already exists; otherwise, this will create a new structure with the same name.
if (structureManager.getStructuresByName("testScript", permission).isEmpty()){
log.warn "no existing Structure found"
// It is important to note that without the saveChanges() call at the end, the new structure won't be saved to the database and will disappear after the script is run.
structureManager.createStructure().setName("testScript").saveChanges()
} else {
log.warn "found a pre-existing structure"
}


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.