Obtain issue reporter's name for insertion into Jelly script

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

This widget could not be displayed.

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>

This widget could not be displayed.

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.

This widget could not be displayed.

Try this (note that upper case N):

${issue.reporter.displayName}

Hi Jobin,

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

Thanks though.

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

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.

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>

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.

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

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.

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

262 views 1 3
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