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

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

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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

269 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot