Groovy Script to get a list of issuekey, only gives null results

Angel Hernandez
Contributor
March 1, 2025

Scope: I'm trying to run a jql query (it works in the jql search prompt) using a groovy script; to give me a list of issue keys. And it only gives me null results using the Script Runner Console.

Jira Software 9.12.18 - Jira Service Management 5.12.18

Additionally: I want to filter tickets only created between 12am to 8am. According to Grok it should be something like:

def filteredIssues = issues.findAll { Issue issue -> def createdDateTime = issue.getCreated().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() def hour = createdDateTime.getHour() return hour >= 0 && hour < 8 // 00:00 to 07:59

 

Full Code here:

 

 

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
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.issue.search.DocumentWithId

final String DS = "Project = \"Data Support\" and text ~ \"pipeline\""

/**
 * Custom JQL function to find issues created between 12 AM and 8 AM daily
 */
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def query = jqlQueryParser.parseQuery(DS)

def searchResults = searchProvider.search(SearchQuery.create(query, user), PagerFilter.unlimitedFilter)
def issues = searchResults.getResults()

def issueKeys = issues.collect { DocumentWithId docWithId ->
    def doc = docWithId.getDocument()
    doc.get("issuekey")
}

issueKeys.each { key ->
    log.info("Issue Key: ${key}")
}

// Return the list of keys
return query

 

 

1 answer

0 votes
Angel Hernandez
Contributor
March 1, 2025

Groovy Null results.jpg

Suggest an answer

Log in or Sign up to answer