JQL Search in Script Runner - Return Custom Field Value

I have to automatically get the value of a custom field from one issue put into a scripted field of another issue. I am not doing the search, results and return correctly but don't know where to go for more information.

Issue Type A:

- is the issue type that I'm adding a scripted field to

- has a field called "My Store ID"

- has a scripted field that will contain a working version of the code listed here

Issue Type B:

- is the issue type that I need to search

- has a field called "Store ID" (this is the field in the issue that I need to compare to the value of the other issue's "My Store ID" field)

Other notes:

- The "~" works with an advanced issue search with the "Store ID" field.

- The issueFunction in issueFieldExactMatch() query works as an advanced filter and returns the proper result if I substitute "abc123" with an actual "Store ID" value.

Here is what I am trying (unsuccessfully) to do:

import com.atlassian.jira.issue.Issue;

import com.atlassian.jira.ComponentManager;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.component.ComponentAccessor;

def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("My Store ID");

def abc123 = issue.getCustomFieldValue(field);



def searchResults = issueFunction in issueFieldExactMatch('project = "PROJ" AND issueType = "STORE SUMMARY" AND "Store ID" is not Empty', "Store ID", abc123)

def resultsfield = searchResults.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Store Name");

return resultsfield.toString();

2 answers

0 vote

> def searchResults = issueFunction in issueFieldExactMatch('project = "PROJ" AND issueType = "STORE SUMMARY" AND "Store ID" is not Empty', "Store ID", abc123)

is wrong. You need to get a JqlQueryParser, get a query, and run the query with a SearchService or somesuch. There are examples for this.

Sound like possibly not the most efficient way of doing what you're trying to do, which I admit I didn't totally understand.

How run a simple query and return the result value? Example:

SELECT project.pname from project WHERE project.id='10600'

This code return one value. Test un database client....

Help please...

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

163 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you