Programmatically obtain current Issue, IssueType, Project instance objects in a custom field class?

Laurentiu Nicolae March 14, 2018

Good day.

I am writing a numerical custom field (it extends NumberCFType class) and I need to obtain an instance of the current issue on witch the custom field is being edited/created. I have been searching on the forum, the past couple of days, and have not found any solution to this problem. In some cases I can use the <<getVelocityParameters>> overriden method, to get the issue instance(in create/update screen), but in the view screen this method is not invoked(I belive). Any sugestion is more than welcomed.

1 answer

1 accepted

0 votes
Answer accepted
Johannes Heinzl April 12, 2018

Hello Laurentiu Nicolae,

 

as your NumberCFType extends AbstractSingleFieldType, you can access its methods.

public class NumberCFType
extends AbstractSingleFieldType<Double>

https://docs.atlassian.com/software/jira/docs/api/7.0.2/com/atlassian/jira/issue/customfields/impl/NumberCFType.html

Use the function getValueFromIssue and replace T with Double for your case and return some Double value e.g.: 1.0.

public T getValueFromIssue(CustomField field,
                                     Issue issue)

https://docs.atlassian.com/software/jira/docs/api/7.0.2/com/atlassian/jira/issue/customfields/impl/AbstractSingleFieldType.html#getValueFromIssue-com.atlassian.jira.issue.fields.CustomField-com.atlassian.jira.issue.Issue- 

 

Example:

public Double getValueFromIssue(CustomField field, Issue issue) { return 1.0; }

 

The function getValueFromIssue should be called every time the customfield is accessed via the jira UI. Therefore you should always get the current Issue as the variable issue.

 

Kind regards,

Johannes

Laurentiu Nicolae April 13, 2018

Thank you kindly for your answer, your answer is right on the spot. Actually I needed to do this for a certain scenario that needed to modify the value of that particular custom field, to all the issues of a certain type in a project. For that I used a listener to retrieve the necessary information on certain operations(Create/Update and Delete).

Johannes Heinzl April 13, 2018

You're welcome.

Suggest an answer

Log in or Sign up to answer