ScriptRunner Change status on a issue based on condition

Søren Hansen January 10, 2023

Hello everyone. We have a number of issues with a given status. I would like to change their status when they have been inactive for a given period of time.

Is it possible to create a script in scriptrunner that can do exactly this?

1 answer

1 accepted

1 vote
Answer accepted
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 10, 2023

Hi @Søren Hansen 

Yes this would be possible to be created in Scriptunner under "Job". I mean this script should run e.g. everyday at midnight and gather all issues which satisfy your conditions.

Søren Hansen January 10, 2023

How would the script look like. I need some ideas.

Søren Hansen January 11, 2023

I have something like this, it looks if the issue is more than 6 months inactive:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.web.bean.PagerFilter
import org.joda.time.DateTime

// Get the Jira Service Desk instance
def jira = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

// Get the project key
def projectKey = "MY_PROJECT_KEY"

// Get all issues in the project that have a status different than resolved
def searchResults = ComponentAccessor.searchProvider.search("project = '" + projectKey + "' and status != 'Resolved'", jira, PagerFilter.getUnlimitedFilter())

// Get all the issues
def issues = searchResults.getIssues()

// Define date 6 months ago
def sixMonthsAgo = new DateTime().minusMonths(6)

// Iterate through all issues and change status if inactive for 6 months
for (Issue issue : issues) {
def lastComment = issue.getComments().last()
if (!lastComment || lastComment.getCreated().toDate() < sixMonthsAgo.toDate()) {
issue.setStatus("Resolved")
}
}

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2023
Like # people like this
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2023

I agree with what @Fabio Racobaldo _Herzum_ told you.

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events