Is it possible in Java to retrieve an array of possible options that a user is offered in a custom multi-check field?
For example, my multi-check field 'ManyOptions' has 3 true/false options: "Option1", "Option2", "Option3". I can successfully retrieve an array containing all options that are marked True ([ "Option1", "Option2" if the first and second are checked, for example).
If I could retrieve an array of all available options, then I can compare the two arrays to see if a user has checked all, some, or none.
I am using JIRA 5.2 with the 'Misc Custom Fields' plugin and with the following code:
<!-- @@Formula:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
String sumCustomFieldValues( String customFieldId, Issue theIssue ) {
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
String val = "";
if(theIssue.getCustomFieldValue(customField) != null) {
try {
val = String.valueOf(theIssue.getCustomFieldValue(customField)).toString();
} catch (Exception e) {
}
}
val = theIssue.getCustomFieldValue(customField).getClass().getName();
return val;
}
sumCustomFieldValues("customfield_10001", issue.getIssueObject());
-->
The returned value is dummied a bit to just return a String for debugging purposes.
You should look into com.atlassian.jira.issue.fields.CustomField#getOptions(java.lang.String, com.atlassian.jira.issue.fields.config.FieldConfig, com.atlassian.jira.issue.context.JiraContextNode). You call it on your custom field object, passing:
Excellent, thank you. I've used this code successfully:
<!-- @@Formula:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
String sumCustomFieldValues( String customFieldId, Issue theIssue ) {
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
int currentOptionCount;
int availableOptionCount;
if(theIssue.getCustomFieldValue(customField) != null) {
try {
Object relConfig = customField.getRelevantConfig(theIssue);
Object availableOptions = customField.getOptions(null, relConfig, null);
currentOptionCount = theIssue.getCustomFieldValue(customField).size();
availableOptionCount = availableOptions.size();
} catch (Exception e) {
}
}
String estimationStatus;
if (currentOptionCount == availableOptionCount){
comparisonResult = "Complete";
} else {
comparisonResult = "Incomplete";
}
return comparisonResult;
}
sumCustomFieldValues("customfield_10001", issue.getIssueObject());
-->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool.
Don't forget to "accept" an anwser, so that the Question can be considered as "Answered".
David
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.