Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script for Archiving Structures by using Structure ID or Name

Sriram Pallapothu October 7, 2022

Is there any script to pass specific Structure ID's or names and to archive only those structures. 

Why because we identified few structures for which owners are active and not using  so we want to archive those Structures for few days if no one comes back after specific time interval we will delete them. 

Please suggest to archive structures by using ID or structure names. 

1 answer

0 votes
Vikrant Yadav
Community Champion
October 9, 2022

Hi @Sriram Pallapothu  For this you need scriptrunner plug-in and run following script in script console , it archives all the structure in which owner is an inactive user :- 

Thanks to Script creator / owner @David Niro 

import com.atlassian.jira.component.ComponentAccessor

def plugin = ComponentAccessor.pluginAccessor.getPlugin('com.almworks.jira.structure')
def loader = plugin.classLoader
def PermissionLevel = loader.loadClass('com.almworks.jira.structure.api.permissions.PermissionLevel')
def StructureAuth = loader.loadClass('com.almworks.jira.structure.api.auth.StructureAuth')

def structureComponents = plugin.getModuleDescriptor('structure-components').module
def structureManager = structureComponents.structureManager

StructureAuth.sudo {
def activeStructures = structureManager.getAllStructures(PermissionLevel.NONE, false)
def structuresToArchive = activeStructures.findAll { it.owner != null && !it.owner.isActive() }
structuresToArchive.forEach {
it.setArchived(true).saveChanges()
log.warn("Archived structure: ${it.id} - ${it.name}")
}
structuresToArchive
}

Thanks

V.Y

Suggest an answer

Log in or Sign up to answer