Groovy script for seeing if issue is in JQL Query

Victor Graham 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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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