I used the following code to get issues via a JQL:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
// Set log level to INFO
log.setLevel(Level.INFO)
// The JQL query you want to search with
final jqlSearch = "issuetype = 'SUD Modul' and 'Sommersemester aktiv?' = aktiv"
// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.valid) {
log.error('Invalid query')
return null
}
try {
// Perform the query to get the issues
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results
issues.each {
log.info(it.key)
}
issues*.key
} catch (SearchException e) {
e.printStackTrace()
null
}
which works and when I excecute this in the console I also receive an Issue e.g. [SUD-42].
Because I want to extend this script and buit a scheduled job, I need to retrieve informations of that issue. E.g. I need to know the assignee and the value of an customfield, but I cant use codes like:
def assignee = issues.getAssignee()
The programm then states that issues is undeclared. What code can I use, in order to be able to retrieve information from the issue?
Best thanks in advances for your answers!!
Hi,
I'm not sure but your variable issues seems to be a list of all issue retrieve by your JQL. So to get your assignee you need to iterate over your list, like you did it for the issue key and get the assignee.
Hi @Mohamed Benziane this makes sense, thank you!
Do you know how I could do this for instance? I tried sth but it really didnt work :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This line :
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
will return a searchResult object
Then you will be able to get a list of issue with that:
import com.atlassian.jira.issue.Issue
List<issue> = results.getIssues()
for(i in issues){
log.warn(i.getAssignee)
}
I can't test it right now but let me know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i forgot the name of the variable
list<issue> issues = results.getIssues()
you can also try this
def listIssues = results.getIssues()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately it doesnt work either. I tried to add it below the "{...}" construction and within.
If I add it below, the progamm states, that both, the results and the issue variables are undeclared. When I add it in between, the system says that it cannot find matching method ....SearchResult#getIssues().
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes i just found that in the new version of the searchresult class Atlassian removed the getIssues() method.
The old version of the api :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes you are right, so does this mean I cant use a jqlSearch to get issues?
In principle it has to be possible, to search for issues (via sql) and then write an email to the appropriate assignees
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.parser.JqlQueryParser
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// edit this query to suit
def query = jqlQueryParser.parseQuery("project = SUD and issuetype = 'SUD Modul' and 'Sommersemester aktiv?' = aktiv")
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${search.total}")
search.results.each { documentIssue ->
log.debug(documentIssue.key)
// if you need a mutable issue you can do:
def issue = issueManager.getIssueObject(documentIssue.id)
// do something to the issue...
def issueAssignee = issue.assignee())
}
I also tried this code but it also doesnt work. Same problem: issue is undeclared
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.