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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,416
Community Members
 
Community Events
184
Community Groups

Display the results of a JQL search in a custom field

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

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:

https://community.atlassian.com/t5/Jira-questions/Is-it-possible-to-have-a-scripted-select-list-which-contain/qaq-p/1211810#U1216440

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

Thanks and Regards,

Swapnil Srivastav

@Joshua Yamdogo _ Adaptavist 

Am working on something similar.

Hi,

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 = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
results.getIssues().each { documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
def release = customFieldManager.getCustomFieldObjectByName("Release")
log.warn("789")
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.
Jul 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.search.SearchProvider
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 = searchProvider.search(query, 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(documentIssue.id)
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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events