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");
Community moderators have prevented the ability to post new answers.
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();
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';
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you want to get issue which have that external refernce right? if yes then check my answer i have updated
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.