Missed Team ’24? Catch up on announcements here.

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

Find collection of issues by customfieldvalue

Graeme Mitchell August 7, 2013

I have a custom field configured within Jira which stores an external reference (text only custom field). I have a plugin whereby I need to return a collection of issues that contain that external reference number. I want to use the api to do so of course, but am not quite sure how to code it. This psuedo gives an idea of what I'm trying to do (the findByValue method is obviously bogus):-

CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("My Field");
Collection<Issue> issues = customField.findByValue("My External Reference");

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
RambanamP
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.
August 7, 2013

what is mean by external reference number? text field will return object of String.

following way you can get custom field value

CustomField cf = customFieldManager.getCustomFieldObjectByName("CustomField Name");	
String cfValue=(String)issue.getCustomFieldValue(cf );	
JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder();
Query query = builder.customField(cf.getIdAsLong()).like(cfValue).buildQuery();
SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
SearchResults searchResults = searchProvider.search(query, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),PagerFilter.getUnlimitedFilter());
List<Issue> issues = searchResults.getIssues();

Graeme Mitchell August 7, 2013

Thanks for your reply, but I'm not sure you're following what I'm trying to do. In the code you have, you assume I'm trying to get the value of a custom field for a specific issue which is already known. This is not what I'm trying to achieve.

I want to find a collection of issues based on the value contained within a specific custom field, containing an external reference. What this external reference represents isn't relevant, but by external reference I just mean the string value contained within the customfield. There could be one issue which has this value in my custom field, or there could be many issues. Here is an SQL representation of what I'm trying to do if it helps. I just want to do this through the API without querying directly:-

SELECT ji.pkey
FROM jiraissue ji
  INNER JOIN customfieldvalue cfv
    ON ji.id = cfv.issue
  INNER JOIN customfield cf
    ON cf.id = cfv.customfield
WHERE cf.cfname = 'myCustomFieldName'
  AND cfv.stringvalue = 'myExternalReference';

RambanamP
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.
August 7, 2013

you want to get issue which have that external refernce right? if yes then check my answer i have updated

Graeme Mitchell August 7, 2013

Perfect, that's what I needed. Here's the full code I used for anybody needing it:-

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("myCustomField"); 		
JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder();
Query query = builder.customField(cf.getIdAsLong()).like("myExternalRef").buildQuery();
SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
SearchResults searchResults = searchProvider.search(query, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),PagerFilter.getUnlimitedFilter());
Collection<Issue> issues = searchResults.getIssues();

TAGS
AUG Leaders

Atlassian Community Events