Obtain issue reporter's name for insertion into Jelly script

UoS Web Team People November 7, 2012

We are in the process of implemention Jelly scripts as per Atlassian's Jelly Escalation examples. Whilst we can get them to work as-is, what we would like to do is include the issue reporter's name in the comment.

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log">
<jira:Login username="****" password="********">
	<log:info>Running close resolved issues service</log:info>
	<!-- Properties for the script -->
	<core:set var="comment">Hello XXXX,

This issue has been in state 'Resolved' for one week and has now been closed.

If this issue has not been completed or you are not satisfied with the resolution, please reopen the issue and we will respond as soon as possible.

Thank you.</core:set>
	<core:set var="workflowStep" value="5"/>
	<core:set var="workflowUser" value="****"/>
	<core:set var="filterID" value="10501"/>
	
	<!-- Run the SearchRequestFilter -->
	<jira:RunSearchRequest filterid="${filterID}" var="issues"/>

	<!-- Iterate over the issues -->
	<core:forEach var="issue" items="${issues}">
		<log:info>Closing resolved issue ${issue.key}</log:info>
		<jira:TransitionWorkflow key="${issue.key}" user="${workflowUser}" workflowAction="${workflowStep}" comment="${comment}"/>
	</core:forEach>
</jira:Login>
</JiraJelly>

I have tried various methods of obtaining the reporter's name, including those already asked on Atlassian Answers, but I am not able to get them to work on JIRA v5.1.7.

<core:invoke on="${issue}" method="getReporter" var="reporter"/>

Whilst the Jelly Runner accepts this, it doesn't seem to work. Therefore, please can you give us some guidance.

Thanks a lot!

3 answers

1 accepted

0 votes
Answer accepted
UoS Web Team People November 8, 2012

Working solution as per Jobin's code suggestion:-

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log">
<jira:Login username="****" password="********">
    <log:info>Running close resolved issues service</log:info>
    <!-- Properties for the script -->
    <core:set var="workflowStep" value="5"/>
    <core:set var="workflowUser" value="****"/>
    <core:set var="filterID" value="10501"/>
     
    <!-- Run the SearchRequestFilter -->
    <jira:RunSearchRequest filterid="${filterID}" var="issues"/>
 
    <!-- Grab an instance of ComponentAccessor -->
    <core:invokeStatic className="com.atlassian.jira.component.ComponentAccessor" method="getIssueManager" var="issueManager"/>
    
    <!-- Iterate over the issues -->
	<core:forEach var="issue" items="${issues}">
		<core:invoke on="${issueManager}" method="getIssueObject" var="issueObj">
			<core:arg type="java.lang.String" value="${issue.key}"/>
		</core:invoke>
		<core:invoke on="${issueObj}" method="getReporter" var="reporter"/>
		<log:info>Closing resolved issue ${issue.key}</log:info>
        <jira:TransitionWorkflow key="${issue.key}" user="${workflowUser}" workflowAction="${workflowStep}" comment="Hello ${reporter.displayName},
 
This issue has been in state 'Resolved' for one week and has now been closed.
 
If this issue has not been completed or you are not satisfied with the resolution, please reopen the issue and we will respond as soon as possible.
 
Thank you."/>
	</core:forEach>
    
</jira:Login>
</JiraJelly>

0 votes
Jobin Kuruvilla [Adaptavist]
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.
November 7, 2012

Try this (note that upper case N):

${issue.reporter.displayName}

UoS Web Team People November 7, 2012

Hi Jobin,

Thank you for your help, but unfortunately it didn't appear to work.

Thanks though.

Jobin Kuruvilla [Adaptavist]
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.
November 7, 2012

how are you using it? what is the full code?

UoS Web Team People November 7, 2012

Hi Jobin,

I originally tried the above code but with

${issue.reporter.displayName}

in place of XXXX, but realising that the comment variable had already been defined before the issue details were obtained and that it might not get refreshed, I then tried replacing the ${comment} placeholder with the comment string itself, but this didn't work either.

In order to see if the reporter name was being returned I replaced the forEach block with

<core:forEach var="issue" items="${issues}">
        <log:warn>${issue.key} : ${issue.reporter.displayName}</log:warn>
    </core:forEach>

and whilst the issue key appears in the log files, the reporter name does not. (Note: Using ${issue.reporter} prints the username of the reporter, though.)

Hope this helps and thanks in advance.

Jobin Kuruvilla [Adaptavist]
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.
November 8, 2012

How about this?

<core:forEach var="issue" items="${issues}">
	<core:invoke on="${issue}" method="getReporter" var="reporter"/>
    <log:warn>${issue.key} : ${reporter.displayName}</log:warn>
</core:forEach>

UoS Web Team People November 8, 2012

Thank you for this but unfortunately it threw:

Could not run script.
Extra Information: [hide]

Error: <JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log">
Exception: org.apache.commons.jelly.JellyTagException: null:21:0: No such accessible method: getReporter() on object: org.ofbiz.core.entity.GenericValue
java.io.PrintWriter@7f7a4147

when I ran it in Jelly Runner.

Jobin Kuruvilla [Adaptavist]
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.
November 8, 2012

Ah wait, is $issue a Issue object? Looks like it is a GenericValue. You will have to get the Issue object before doing this.

UoS Web Team People November 8, 2012

Oh right, how do I get the Issue object? I assume that it involves some kind of invokation and needs to be placed inside that iterator?

I tried implementing the IssueObject as per this suggestion but Jelly Runner threw an exception about the IssueManager.

Jobin Kuruvilla [Adaptavist]
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.
November 8, 2012

Maybe something like this:

&lt;core:invokeStatic className="com.atlassian.jira.component.ComponentAccessor" method="getIssueManager" var="issueManager"/&gt;
&lt;core:forEach var="issue" items="${issues}"&gt;
	&lt;core:invoke on="${issueManager}" method="getIssueObject" var="issueObj"&gt;
		&lt;core:arg type="java.lang.String" value="${issue.key}"/&gt;
    &lt;/core:invoke&gt;
    &lt;core:invoke on="${issueObj}" method="getReporter" var="reporter"/&gt;
    &lt;log:warn&gt;${issue.key} : ${reporter.displayName}&lt;/log:warn&gt;
&lt;/core:forEach&gt;

UNTESTED

UoS Web Team People November 8, 2012

Thank you very much Jobin, that works perfectly! :-D

0 votes
UoS Web Team People November 7, 2012

I have noticed that

${issue.reporter}

works by returning the reporter's username but

$(issue.reporter.displayname}

doesn't return anything, nor does

${issue.reporter.fullname}

I feel that this is the right line to go down but can't be sure.

Suggest an answer

Log in or Sign up to answer