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

This widget could not be displayed.

> 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.

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

534 views 3 19
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