Displaying multiple rows from Map object into VM file.

I am trying to implement a JIRA report module. For this I am making use of the AbstractReport class which has generateReportHtml() method.
I have the following data that is being passed from java class to vm file:
Map<String, Object> velocityParams = new HashMap<String, Object>();
...
velocityParams.put("issueKey", issueKey);
velocityParams.put("userName", userName);
velocityParams.put("updateDate", updatedDate);
velocityParams.put("fromIssueType", fromIssueType);
velocityParams.put("toIssueType", toIssueType);
return descriptor.getHtml("view", velocityParams);
I want to display all the data through vm file
But I am unable to display multiple rows using foreach loop
Thanks in advance

3 answers

I have raised the same question Here

I have raised the same question here

0 vote

Can you give a snippet of the velocity template code you are using to iterate over the map?

At a guess you probably need to do the foreach loop on the map's entrySet. Something like:

#foreach ($mapEntry in $velocityParams.entrySet())
<tr>
<td>$mapEntry.key</td> <td>$mapEntry.value</td>
</tr> #end

If this doesn't help or you don't get a better answer on here, consider posting your question in Atlassian's dedicated developer community: https://developer.atlassian.com/community/

That's the better place for dev related questions like this.

Edit: Fixed URL.

 

This is the snippet we used for displaying single row in the vm file. But we are unable to display multiple rows using foreach loop.

<tr>
    <td> $issueKey</td>
    <td>$userName</td>
    <td>$updateDate</td>
    <td>$fromIssueType</td>
    <td>$toIssueType</td>
</tr>

 Thanks,

Pooja Singh.

This is the snippit we used for displaying single row in the vm file. But we are unable to display multiple rows using foreach loop

<tr>
    <td> $issueKey</td>
    <td>$userName</td>
    <td>$updateDate</td>
    <td>$fromIssueType</td>
    <td>$toIssueType</td>
</tr>
 


 

This is the snippit we used for displaying single row in the vm file. But we are unable to display multiple rows using foreach loop
<tr>
<td> $issueKey</td>
<td>$userName</td>
<td>$updateDate</td>
<td>$fromIssueType</td>
<td>$toIssueType</td>
</tr>

Please reply on the same

So you have a collection of issues from somwhere that you are want to loop over?

There are examples in this tutorial showing use of a for each loop in the vm template: https://developer.atlassian.com/jiradev/jira-platform/guides/projects/tutorial-creating-a-jira-report

For example, you can find this snippet in the tutorial:

#foreach ($issue in $issues)
   <tr>
      <td width="5%">&nbsp;</td>
      #issueLineItem ($issue)
      <td nowrap>
         #if($issue.getAssignee())
            $issue.getAssignee().getDisplayName()
         #else
            $i18n.getText('common.concepts.unassigned')
         #end</td>
       <td nowrap>$outlookDate.format($issue.getUpdated())</td>
   </tr>
#end

But for this to work you need to have got a collection of issues to do the foreach on from somewhere.

I don't see you doing that anywhere in the code you have posted.

Perhaps it will help if you study the code in the tutorial to see where it comes from in that example.

#foreach ($mapEntry in $velocityParams.entrySet())
<tr>
<td>$mapEntry.key</td>
<td>$mapEntry.value</td>
</tr>
#end

This code is not working for me. something gonna wrong

Still I am getting problem to show data on Velocity template using GetHtml method.

Kindly Please reply me on this

 

Sam Hall Community Champion May 28, 2017

Hi Prashant - can you give more information so that someone in the community may help you? We're users just like you, so it is difficult to help without more details.

When you say 'not working', what is not working? Code won't compile? Run-time error? Not displaying what you expect?

What error messages you are seeing? 

If no error message, please give some more details about what you are trying to display. What are you expecting to see? What do you actually see?

I would also recommend you try asking for help on the dedicated developer's community. It is much better suited to questions like this: https://developer.atlassian.com/community/

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,305 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot