Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Display the results of a JQL search in a custom field

Praveen July 25, 2017

Hi, I am trying to configure a behaviour that will display the results of a JQL search in a Custom field of similar issue.

The basic idea is I need to display the field values previous issues similar to the current issue (where the custom field is available)

3 answers

Suggest an answer

Log in or Sign up to answer
0 votes
SWAPNIL SRIVASTAV November 1, 2019

Hi Joshua Yamdogo @ Adaptavist  and @kumar jira

Could you please let me know how to fetch the value of a custom field and summary of issues fetched from JQL query and then concatenate the two to make an option of a select list custom field. Here's the detailed explanation:

It is very urgent and important for me. Any help would be appreciated.

Thanks and Regards,

Swapnil Srivastav

0 votes
kumar jira September 10, 2019

Joshua Yamdogo @ Adaptavist 

Am working on something similar.


Using behaviors i would like to get list of a field values from  issues result of a JQL.

[For example, the field name is "Field 123", 

I want to pass a JQL from behaviors and get the list of "Filed 123" values from all the issues.]


This is what i tried.

def query = jqlQueryParser.parseQuery("issuetype = 'Some issue type' and status != 'Not Implement'")
def searchRequest = new SearchRequest(query)
def results =, user, PagerFilter.getUnlimitedFilter())
results.getIssues().each { documentIssue ->
def issue = issueManager.getIssueObject(
def release = customFieldManager.getCustomFieldObjectByName("Release")
def releaseval = issue.getCustomFieldValue(release)
def optionsMap2 = [:]

Thank you. 

0 votes
Joshua Yamdogo @ 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.
July 25, 2017

Hi Praveen,

I would probably not use a behaviour for this. The reason being is that every time you do anything to the issue (Create, Transition, Edit, etc) the behaviour will run the JQL function repeatedly. You could try putting the code in an initializer function behaviour, but there is currently an open bug about not being able to set formField values in intializers, so I don't know if that would work.

Instead, I'd set up a Script Listener that is applied to the specific project you want to set values for. You can set the Script Listener to fire on "Issue Created" so that the field gets set whenever a new issue in that project is created.

Below is a script that runs a specific JQL query. Once it gets the results from that query, it loops through the issues from the result. In my script, I match an issue that has a key of "JRA-2". If I find that specific key, I get the custom field value from that issue. After I get the custom field value from that issue, I update the custom field value for the current issue. Below is the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// The search query
def query = jqlQueryParser.parseQuery("project = JRA")

// Results from query
def results =, user, PagerFilter.getUnlimitedFilter())

// Get the custom field that you want to update
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("TextFieldA")
def valueFromPreviousIssue

// Loop through the search results. If the key of one of those issues matches, grab the value from its custom field
results.getIssues().each { documentIssue ->
def oldIssue = issueManager.getIssueObject(
if (oldIssue.key == "JRA-2") {
def oldCustomField = customFieldManager.getCustomFieldObjectByName("TextFieldA")
valueFromPreviousIssue = oldIssue.getCustomFieldValue(oldCustomField)
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), valueFromPreviousIssue), new DefaultIssueChangeHolder())

Note that you will obviously need to change the JQL query to match what you want to search for. You'll also need to change the part in the loop, since you don't want to match for "JRA-2".

You might get static type checking errors when you use this code, but you can ignore this. I've tested the script and can see that it works.

AUG Leaders

Atlassian Community Events