I'm trying to get a value from a specific field that determines at runtime. I was trying to check for fields by calling issue.getFields(), but it still returns null. The only one kind of method that returns value properly - method with specified in advance field (example:
issue.getSummary();)
Main method
JiraRestClient restClient = getJiraRestClient(); \\custom method for connecting in jira local server
SearchRestClient searchClient = restClient.getSearchClient();
SearchResult searchResult = searchClient.searchJql(jql, -1, 0, fields).claim();
JsonArrayBuilder issueArrayBuilder = Json.createArrayBuilder();
for (Issue issue : searchResult.getIssues()) {
Issue initIssue = restClient.getIssueClient().getIssue(issue.getKey()).claim();
JsonObjectBuilder jsonIssueBuilder = Json.createObjectBuilder();
for (String field : fields) {
JsonValue jsonValue = getJsonValueForField(initIssue, field);
jsonIssueBuilder.add(field, jsonValue);
}
JsonObject jsonIssue = jsonIssueBuilder.build();
issueArrayBuilder.add(jsonIssue);
}
return issueArrayBuilder.build();
private static JsonValue getJsonValueForField(Issue issue, String field) {
IssueField issueField = issue.getField(field);
The Issue interface does not provide a method called "getField()" (see https://docs.atlassian.com/software/jira/docs/api/9.10.0/com/atlassian/jira/issue/Issue.html )
To fetch the value of a custom field you need to get the custom field as CustomField object and use the "getCustomFieldValue()" method of the actual Issue then.
For instance:
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()
CustomField customFieldObject = cfManager.getCustomFieldObjectsByName("Foo").first()
def customFieldValueOfIssue = issue.getCustomFieldValue(customFieldObject)
There is also an interface FieldManager available to work with fields in a generic way.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.