Is it possible to call a method from Customfield?

Hello,

I have created a customfield and I have different methods to get the value. E.g. I have a method getValueWithId(). So the value of the customfield shows the let`s say lastName and the getValueWithId is personId, lastName. I am able to get the customfieldvalue as follows:

final CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

    	final CustomField customField = customFieldManager.getCustomFieldObjectByName(CONTACT_CUSTOM_FIELD_NAME);

    	if(customField != null) {
	    	final Object customFieldValue = getIssueObject().getCustomFieldValue(customField);
	
	    	if(customFieldValue != null && customFieldValue instanceof String) {
	    		String newCustomFieldValue = (String)customFieldValue;

Now I want to access the customField value from a class that extends a JiraWebActionSupport. I am able to access the value, but I want to directly call the getValueWithId() method from the customField class.

It`s all working as expected, my only problem is, that I have duplicated code within the customField and the class that extends the JiraWebActionSupport.

Thank you.

2 answers

0 vote
Timothy Chin Community Champion Feb 20, 2014

If you cast your customfield to the right class, you can use the method of that class right?

I tried this by checking the name of the returned customField object.

LOGGER.debug("customField: " + customField.getClass().getName());

writes

customField: com.atlassian.jira.issue.fields.CustomFieldImpl

But thats not my class. My class is EmailNotificationCustomField extends GenericTextCFType. Maybe it`s that easy as you describe, but where do I cast?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 4 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

16 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you