Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

run a query in ScriptRunner JQL to know the number of issues in a project that were last updated mor

I would like to run a query in ScriptRunner JQL to know the number of issues in a project that were last updated more than 1 year ago. I am using the following code in the script console:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import java.text.SimpleDateFormat
import com.atlassian.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.DelegatingApplicationUser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

def log = Logger.getLogger("atlassian-jira.log")

List<Project> prList = ComponentAccessor.getProjectManager().getProjectObjects()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

for(Project myproject: prList){

def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService.class)
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def lastUpdatedDate = new Date(Long.MIN_VALUE)
def builder = JqlQueryBuilder.newBuilder()
def query = builder.buildQuery()

// edit this query to suit
def query2 = jqlQueryParser.parseQuery("project = "+myproject.getKey()+" and updated < 2021-08-25")

def results2 =, user, PagerFilter.getUnlimitedFilter())

log.warn("Total issues: ${}")

log.warn("Project name "+myproject.getName()+" |||Date: "+lastDate + " ||| number of issues: "+results.getResults().size() + " ||| Project Lead: "+ myproject.getProjectLead() +" ||| List of Admins: "+admins)


I am getting the error:
**groovy.lang.MissingMethodException: No signature of method: is applicable for argument types: (com.atlassian.query.QueryImpl, com.atlassian.jira.user.DelegatingApplicationUser...) values: [{project = "EAP"} AND {updated < "2021-08-25"}, mouh(JIRAUSER59200), ...]
Possible solutions: search(, com.atlassian.jira.web.bean.PagerFilter), search(, com.atlassian.jira.web.bean.PagerFilter, java.util.Set), search(,, each(groovy.lang.Closure)

but I am using some really simple code that I have found online in the scriptrunner website.
Anyone knows what I need to fix in order to be able to fix my problem and run my query?

1 answer

0 votes

I prefer to use the "SearchService" to perform searches

Try this bit of code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import groovy.xml.MarkupBuilder

def searchService = ComponentAccessor.getComponent(SearchService)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.table {
th "Project Name"
th "Old Issue Count"
th "Project Lead"
def allProjects = ComponentAccessor.projectManager.projectObjects
allProjects.each { project ->
def jql = "project=$project.key and Update < -365d"
def parseResult = searchService.parseQuery(currentUser, jql)
assert parseResult.valid: parseResult.errors
def resultCount = searchService.searchCount(currentUser, parseResult.query)
log.warn "Total issues: $resultCount"

td resultCount

If you want to access the individual issues:

def results =, parseResult.query, PagerFilter.unlimitedFilter).results
results.each{issue-> "issue: $issue.key"

But be careful with "unlimitedFilter". If you have a lot of issues. The "results" variable can be very large and fill up all your memory.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events