Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to look for the current issue while doing a JQL inside a groovy script?

Mihai Mihai
Contributor
September 9, 2019

Hello,

I am wondering if it's possible to run a query inside a groovy script, for the current issue for which the script is being executed (as a post function on a transition):

 

For regular JQL, we would use:

 

def jql = "project = ABC and issuetype = Epic"

 

But what we would need is:

 

Issue issue = issue
def issuekey = issue.getKey()

def jql = "project = ABC and issuetype = Epic and issueFunction in linkedIssuesOf('issuekey =" + issuekey+ "')'"   //not working, of course

 

Would something like this be possible?

 

Thank you!

1 answer

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
September 20, 2019

What's your ultimate goal?

If you can get the correct JQL, do you intend to run the query then examine the results all in code? (that's possible using the JqlQueryParser component)

If so, why not just access the linked issue via the JAVA API? That's what scriptrunner is for.

def issueLinkManager = ComponentAccessor.issueLinkManager
def links = issueLinkManager.getLinkCollection(issue, ComponentAccessor.jiraAuthenticationContext.loggedInUser)
links.allIssues.findAll{ linkedIssue->
linkedIssue.projectObject.key == 'ABC' && linkedIssue.issueType.name == 'Epic'
}.each{linkedEpic->
//do something to linkedEpic
}

Mihai Mihai
Contributor
September 22, 2019

Hi,

 

Yes, my goal here is to count how many related issues there are. I also considered going through the linked issues, but I was curious if it was possible to run a query for the current one. I eventually found:

 

Issue issue = issue
def currentfeaturerequest = issue.getKey()

def jql = "project = ABC and issuetype = Epic and issueFunction in linkedIssuesOf('issuekey = ${currentfeaturerequest}')"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events