Missed Team ’24? Catch up on announcements here.

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

Plugin Upgrade for JIRA 5 : How to get values from custom field (Cascading Select )

Hussain Misbah September 6, 2012

Hi Everyone,

I have a custom plugin/events listener that I am rewriting to support JIRA 5.

but I am getting an exception , can anyone help fix this, or show a sample of how to get values from cascading select field using JIRA 5 SDK.

JIRA 4:

{code}

Issue currentIssue = event.getIssue();
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
MutableIssue mutIssue = issueManager.getIssueObject(currentIssue.getKey());
CustomFieldManager cfm = ComponentManager.getInstance().getCustomFieldManager();
CustomField customField = ManagerFactory.getCustomFieldManager().getCustomFieldObjectByName("MyCascadeSelect");
CustomFieldParamsImpl params = (CustomFieldParamsImpl) currentIssue.getCustomFieldValue(customField);

LazyLoadedOption option1 = (LazyLoadedOption) params.getFirstValueForNullKey();
LazyLoadedOption option2 = (LazyLoadedOption) params.getFirstValueForKey("1");

String value1 = option1.getValue();
{code}

JIRA 5


{code} Issue currentIssue = event.getIssue();
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue mutIssue = issueManager.getIssueObject(currentIssue.getKey());
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("MyCascadeSelect");
// System.out.println(customField.getCustomFieldType().getName()); //cascading select
// System.out.println(currentIssue.getCustomFieldValue(customField).getClass().getName()); //HashMap

HashMap value = (HashMap)currentIssue.getCustomFieldValue(inRegardsTo);
// System.out.println(value.size()); //2
// System.out.println(value.values().toArray()[0].getClass().getName()); // LazyLoadedOption

CustomFieldParamsImpl params = (CustomFieldParamsImpl) currentIssue.getCustomFieldValue(customField); // exception :
// java.lang.ClassCastException: java.util.HashMap cannot be cast to com.atlassian.jira.issue.customfields.view.CustomFieldParamsImpl

{code}

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Hussain Misbah September 6, 2012

here is the solution to share :

LazyLoadedOption option1 = (LazyLoadedOption) params.getFirstValueForNullKey();

will become

LazyLoadedOption option1 = (LazyLoadedOption) value.values()toArray()[0];

xuhai zhao September 13, 2012

thank you very much, I just used your solution and it worked well.

0 votes
Hussain Misbah April 29, 2014

I am glad this is helpful for other users ..I need to resolve this question and my second comment is the right answer.

TAGS
AUG Leaders

Atlassian Community Events