Skip to main content
Book your demo
Example scripts
To homepage
Jira
Cloud icon
Cloud

Archive work items returned by a JQL Search

Created 2 year(s) ago, Updated 0 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
groovy
// Construct the JQL to return the work items to be archived
def jqlQuery = "updated >= '-30d' and project = 'RRR'"

// Loop over each work item
def archivedWorkItems = WorkItems.search(jqlQuery).take(500).collect { workItem ->
    // Archive the current work item
    def archiveWorkItem = put("/rest/api/3/issue/archive")
            .header("Content-Type", "application/json")
            .body(
                    issueIdsOrKeys: [workItem.key]
            )
            .asObject(Map)

    // Validate the work item was archived correctly
    assert archiveWorkItem.status >= 200 && archiveWorkItem.status < 300
    workItem.key
}

logger.info("The following work items were archived succesfully: ${archivedWorkItems}")
Having an issue with this script?
Report it here