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

How to get custom field value

pamela guo December 19, 2012

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
int sumCustomFieldValues( string customFieldId) {
int sum = 0;
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
if(issue.getCustomFieldValue(customField)!=null){
sum = 1;
}
return sum;
}
sumCustomFieldValues("customfield_10003");
Question: This code works fine. Customfield_10003 is a select list, how can I get the selected value/Index?
I am using JIRA 5.1 download.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
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.
December 19, 2012
Option selectedVal = (Option) issue.getCustomFieldValue(customField);
String val = selectedVal.getValue();

pamela guo December 19, 2012

Unfortunately, I tried your code, and val is null.

Option selectedVal = (Option) issue.getCustomFieldValue(customField);
String val = selectedVal.getValue();
Jobin Kuruvilla [Adaptavist]
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.
December 19, 2012

Do you have some value selected on the issue? And make sure the customfield is the select field itself.

pamela guo December 19, 2012

Yes, I did select a value for it. The original code does not work either. TOO BAD

pamela guo December 20, 2012

I can't make it work anyway. I am using a plug-in(Misc Custom Field) and create a Calculated Number Field. I tried to put those code inside this field description with below syntax:

<!-- @@Formula: formula goes here -->
David Kirchner February 13, 2013

This question was marked answered but it's not clear that it was actually answered. What was the solution?

Tuğçe Şahin May 26, 2014
Option selectedVal = (Option) issue.getCustomFieldValue(customField);
String val = selectedVal.getValue();
which library should be used for Option?
2 votes
Roberto Gonzalez July 25, 2013

// gets a reference to the IssueManager and CustomFieldManager manager classes

final CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

// gets a reference to the desired custom field

final CustomField customField = customFieldManager.getCustomFieldObjectByName("custom-field-name");

// retrieves the custom field value object from the issue

final Object customFieldValue = issue.getCustomFieldValue(customField);

// prints value to console

System.out.println("Custom field value: " + customFieldValue);

Sam Huawey December 25, 2015

Your code does not work if there are several custom fields with same name in different projects and they do not share configuration.

Rusi Popov
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.
January 13, 2016

Then use the field's ID (which is String) and call: com.atlassian.jira.issue.CustomFieldManager.getCustomFieldObject(String)

1 vote
Augustin atto December 17, 2014

Hi ,

 

How to create customfieldmanager for particular issue .

 i want to fetch the customfieldobject of particular issue

 

0 votes
Naren
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.
December 19, 2012

try using in the above code -

FieldConfig fieldConfig = customFieldManager.getRelevantConfig(issue);
List&lt;Option&gt; option = ComponentAccessor.getOptionsManager().findByOptionValue("option");

pamela guo December 19, 2012

Thank you, Naren.

List<Option> option = ComponentAccessor.getOptionsManager().findByOptionValue("option");

But I still not get it. This will return a list of options. How can I get the selected option???

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events