Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Capturing the custom field value of an issue.

Bhushan Patil June 3, 2018

Hello Community,

 

I am stuck on this problem since last one week. I am actually creating one addon using Java and Maven which will help me in integrating jira with some other third party tool.

What I want to do is to capture the current values of the fields on the particular issue and pass them to the other tool using webservices. Capturing the same works well for jira default fields but for custom fields nothing seems to be happening. The value always comes out to be null. Following is the snapshot of the code that I have written,

import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

 

public class IssueCreatedResolvedListener implements InitializingBean, DisposableBean {

private final EventPublisher eventPublisher;
public String field = null;
public String fromValue = null;
public String toValue = null;
public String user = null;
public String issueType = null;
public String jiraId = null;
public String silo=null;

public IssueCreatedResolvedListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}

@Override
public void afterPropertiesSet() throws Exception {
// register ourselves with the EventPublisher
eventPublisher.register(this);
}

@Override
public void destroy() throws Exception {
// unregister ourselves with the EventPublisher
eventPublisher.unregister(this);
}

@EventListener
public void onIssueEvent(IssueEvent issueEvent) throws IOException {
Issue issue = issueEvent.getIssue();

CustomField cf=ComponentAccessor.getCustomFieldManager().getCustomFieldObject((long) 14440);
silo=cf.getValueFromIssue(issue);

}

In the above code the field silo is a custom field in our instance and 14440 is the ID of the same. But this value always comes null.

Can you please suggest where I am making any mistakes? Your help would be highly appreciated. Thanks in advance :) :)

2 answers

0 votes
Mikhail_Kopylov
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.
June 3, 2018

Some custom fields may not store a value in the database, mostly fields of third-party plugins.

 

What is the type of field that you're looking for? 

 

If you can navigate database, please check that table `customfieldvalue` has a value for your field and your issue. 

Bhushan Patil June 3, 2018

Hi Mikhail,

 

I have checked in the database and found that there is no value for my desired customfield and issue in Customfieldvalue table.

This customefield is of type com.atlassian.jira.issue.customfields.impl.RenderableTextCFType@225871e1 

Can you please suggest how can I get that value?

Is there any way?

0 votes
Alexey Matveev
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.
June 3, 2018

Hello,

Try like this:

silo = issue.getCustomFieldValue(cf).toString()
Bhushan Patil June 3, 2018

Hi Alexey,

 

Thanks for the reply but this also gave null value :( :(

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events