Forums

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

Run script to all issues

Dan27
Contributor
June 20, 2018

Hi,

I have a script listener- 'issue updated' that work ok,

I would like to run this script to all issues in this project.

how can I define the issue object so he can run on all issues (I will use script console)

2 answers

2 accepted

4 votes
Answer accepted
Marcos Sanchez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2018

Hi,

You can make a JQL in a groovy script that will return an array of all issues in a project and then loop that array and execute your code on that issue.

The code could be something like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)

def issueManager = ComponentAccessor.issueManager

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def projectKey = "DEMO" //THE PROJECT KEY
def queryString = "project = ${projectKey}"

def query = jqlQueryParser.parseQuery(queryString)

def projectIssues = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()).issues.key

projectIssues.each{ issueKey ->
def issue = issueManager.getIssueByCurrentKey(issueKey)
//YOUR CODE
}

 

I recommend to you to run it on a test environment (if you have any) first.

 

 Hope it works for you.

 

Regards,
Marcos

Dan27
Contributor
June 20, 2018

Thanks!!!! Work! :)

Mike Rathwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2019

@Marcos Sanchez I voted for your answer as well as accepting @Mark Markov 's answer. These gave me two parts of things that I... need.

Cheers!

2 votes
Answer accepted
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2018

Hello @Dan27

Or you can get issues via getIssueIdsForProject()

import com.atlassian.jira.component.ComponentAccessor

def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("DS")
def issuesIds = ComponentAccessor.getIssueManager().getIssueIdsForProject(project.id)

issuesIds.each {issueId ->
def issue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
//YOUR CODE HERE
}

 

Hope it helps!

Dan27
Contributor
June 20, 2018

Thanks !! :)

Mike Rathwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2019

@Mark Markov , this variant just solved for part of a thing I am developing and is a clean, elegant way of doing this.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events