Forums

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

Groovy script for seeing if issue is in JQL Query

Victor Graham
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 14, 2021

Hello

 

I'm looking for a Jira groovy script that can check to see if the current issue belongs to a certain jql query. The idea is for it to return true or false. This is to be used as a workflow condition. Is someone able to help?

2 answers

2 votes
David Fischer
Community Champion
December 15, 2021

hi @Victor Graham ,

in JMWE, you can use this snippet:

!!jqlSearch( "key = ${issue.key} AND project = AM" , 1)

(where you can replace  project = AM with whatever JQL condition you need)

However, this is not always reliable in a Workflow Condition, as the Jira index that JQL searches uses might be lagging behind recent changes (because Jira updates its index asynchronously). It is preferable to use a Groovy condition script using JMWE's simplified API (such as issue.get())

1 vote
Nic Brough -Adaptavist-
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.
December 14, 2021

Scriptrunner is never going to have an entire JQL engine written into it to replicate what a JQL search already does.

The simple thing to do here is run the JQL and work with the results.  A search will return a pile of issues, and you can then look through the results to see if the issue or issues you are interested in are there.

A sample script is over at https://library.adaptavist.com/entity/perform-a-jql-search-in-scriptrunner-for-jira

Suggest an answer

Log in or Sign up to answer