Behaviours Plugin - how to return first row from JQL query?

Robert Anston January 27, 2017

Hello,

I have the following code for returning Stories having checkbox set to true. I only have 10 issues with such condition.Could enybody tell me how to return the first, second ..(each row as separate result) row from this query?

Is there any method that I could use for this i.e query.getRow(1), query.getRow(2) ?

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("project = currentProject() AND issuetype = 'Story' AND Active='Yes' ")

Thanks in advance

1 answer

0 votes
JamieA
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.
February 2, 2017

You're just parsing the query there, not actually executing a search. You can get the nth issue like so:

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 user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("project = currentProject() AND issuetype = 'Story' AND Active='Yes' ")

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
results.issues.get(0) // first
results.issues.get(1) // second

Probably wise to check results.total though.

Suggest an answer

Log in or Sign up to answer