How to retrieve details from a current issue?

Hi All,

I am trying to retrieve summary of current issue and display it on an issue tab panel.

this is how i am doing it...

public String retSummary(){
		JiraHelper jiraHelper = new JiraHelper();
		Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
		String summary = currentIssue.getSummary();
		return summary;
	}
 
public void populateVelocityParams(Map params){
params.put("issue", this);
}

and in the velocity template, if i call $issue.retSummary().

i am getting the bellow error in the issue tab panel

An error occurred whilst rendering this message. Please contact the administrators, and inform them of this bug. Details: ------- org.apache.velocity.exception.MethodInvocationException: Invocation of method 'retSummary' in class com.sts.tabpanel.Velocity threw exception java.lang.NullPointerException at com.sts.tabpanel.tabpanel.test4:perforce/templates/tabpanels/perforce.vm[line 15, column 37] at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:337) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:284) at 

and so on...

What mistake have i done? or is it the right way of retrieving current issue details?

if not, please suggest the right way of doing it.

 

Many thanks,

Sharath TS 

9 answers

1 accepted

Accepted Answer
0 votes

Hi All,

Thanks you very much for your valuable inputs. 

i finally solved it.

In The main class which extends AbstractIssueTabPanel and implements IssueTabPanel,

In getAction method, we should pass  "issue.getSummary()" to the velocity class! like the below line.

return Collections.singletonList(new Velocity(super.descriptor, issue.getSummary()))

 

then in velocity constructor, initialize variable this.summary = summary

and params.put("summary", summary)

why don't you directly return the issue.

I'd assume that it's not a good idea to return the whole object with 'this'

Try putting the issue or the summary in the map (e.g. params.put("issue", issue) or params.put("summary", summary) )

and then access your data in the template like:
<p>Summary :$summary</p>

 

public void populateVelocityParams(Map params){
        JiraHelper jiraHelper = new JiraHelper();
        Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
        String summary = currentIssue.getSummary();
		params.put("summary", summary);
}

Hi Florian, Thanks for your reply. I did try doing the way you have mentioned. When it is done this way the whole Activity tab panels disappears! So i am guessing there is some problem in the below lines of code...? JiraHelper jiraHelper = new JiraHelper(); Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); String summary = currentIssue.getSummary();

FYI...the class extends AbstractIssueAction

The three lines above seems to be allright. Did you got any error messages in the log/console ?

The code is returning NULL, any idea?

0 votes

retSummary? Seems you have a typo in there!

No. retSummary() is the method given in the code block

Florian is right, its just a method returning a String.

Sorry, I didn't notice, my bad! Can you use a different variable name instead of issue? I wonder if issue is in the context already or not. Also, I would check inside the retSummary method to make sure it is successfully retrieving summary and there are no NPEs in that method.

I guess that (Issue) jiraHelper.getContextParams().get("issue"); return null and currentIssue.getSummary(); crashes with NullPointerException. Please try to debug the method.

One more though. If it's a case with null issue, you can adjust the code:

Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
        String summary = currentIssue != null ? currentIssue.getSummary() : "";
        return summary;

yes, it is the problem with null. is the code correct? Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); especially .get("issue")

Hi,

Could not obtain the current issue details through java but found a workaround through javascript from the below link

https://answers.atlassian.com/questions/117504

 

Thank you for your inputs.

An answer on how to tackle the NPE or why NPE is showing up in the above java code will be much appreciated!

Sure it's correct. Null means that there is no an issue in the context when a method is invoked. Did you try to add a check for a null as I posted in the answer. It can happen that the method is invoked couple times and when it's invoked first teim there is no issue in the context.

yes, this String summary = currentIssue != null ? currentIssue.getSummary() : ""; code works and ignores NPE. error. but the context here is, lets say i go to a view page of issue TEST-1, which has the issuetabpanel that i have created. In that issue tab panel i need to display details(ex-summary) of TEST-1, likewise details of TEST-2 in its issuetabpanel and so on... the jiraHelper is not fetching details from the current view page of an issue!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

446 views 7 5
Join discussion

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