/
110. Velocity Templates

110. Velocity Templates

Requirement: Display Jira system and custom fields in “Release Notes Section” area in Versions

Below is the code for fetching those fields and displaying them.

Note: Both the files below needs to be updated in order to successfully display the fields.

  1. releasenotes-text.vm

#macro (getReleaseNoteComment $issue $customFieldManager) #set ($customFields = $customFieldManager.getCustomFieldObjects($issue.project.getLong("id"), $issue.issueType.getString("id"))) ## Get ComponentAccessor class to fetch any object #set ($componentAccessorClass = $constantsManager.getClass().getClassLoader().findClass('com.atlassian.jira.component.ComponentAccessor')) #set ($componentAccessorConstructor = $componentAccessorClass.getConstructor()) #set ($componentAccessor = $componentAccessorConstructor.newInstance()) ## Get comments #set ($commentManager = $componentAccessor.getCommentManager().getComments($issue) ) ## Get Components #set ($componentManager = $componentAccessor.getProjectComponentManager().findComponentsByIssue($issue) ) ## Loop to fetch custom field values #foreach($customField in $customFields) #if($customField.name.equals("Service Now #")) #set ($snlabelValues = $customField.getValue($issue)) Service Now No: $snlabelValues #elseif($customField.name.equals("Salesforce Case #")) #set ($sflabelValues = $customField.getValue($issue)) Salesforce Case No: $sflabelValues #elseif($customField.name.equals("Business Units")) #set ($businessUnitValues = $customField.getValue($issue)) #foreach ($bUnits in $businessUnitValues) Business Units: $textUtils.htmlEncode($bUnits.getValue()) #end #end #end #end <title>$action.getText('release.notes.text.title', $project, $version) </title> <body> <table> <tr> <td> #foreach ($issueType in $issueTypes) #if($issueType.issues.size() > 0) <h2>$textUtils.htmlEncode($issueType.name)</h2> <ul> #foreach ($issue in $issueType.issues) <li>[<a xhref='$!appProps.getString("jira.baseurl")/browse/$issue.key'>$issue.key</a>] - $textUtils.htmlEncode($issue.summary) <b>Issue Type</b>: $issue.issueType.name <b>Description</b>: $issue.description <b>Resolution</b>: $issue.resolution.name <b>Status</b>: $issue.status.name <b>Fix Version/s</b>: $issue.fixVersions #getReleaseNoteComment($issue $customFieldManager)</li> #if ($commentManager) #foreach ($comment in $commentManager) <b>Comments</b>: $comment.body #end #end #if ($componentManager) #foreach($component in $componentManager) <b>Components</b>: $component.name #end #end #end </ul> #end #end </td> </tr> <tr> <td> <hr width="100%"> <a name="editarea"><h2>$action.getText('release.notes.edit.copy')</h2></a> <p>$action.getText('release.notes.description')<br></p> <textarea rows="40" cols="120"> $action.getText('release.notes.heading', $project, $version) #foreach ($issueType in $issueTypes) #if($issueType.issues.size() > 0) ** $textUtils.htmlEncode($issueType.name) #foreach ($issue in $issueType.issues) * [$issue.key] - $textUtils.htmlEncode($issue.summary) <b>Issue Type</b>: $issue.issueType.name <b>Description</b>: $issue.description <b>Resolution</b>: $issue.resolution.name <b>Status</b>: $issue.status.name <b>Fix Version/s</b>: $issue.fixVersions #getReleaseNoteComment($issue $customFieldManager) #if ($commentManager) #foreach ($comment in $commentManager) <b>Comments</b>: $comment.body #end #end #if ($componentManager) #foreach($component in $componentManager) <b>Components</b>: $component.name #end #end #end #end #end </textarea> </td> </tr> </table> </body>

 

2. releasenotes-html.vm

#macro (getReleaseNoteComment $issue $customFieldManager) #set ($customFields = $customFieldManager.getCustomFieldObjects($issue.project.getLong("id"), $issue.issueType.getString("id"))) ## Get ComponentAccessor class to fetch any object #set ($componentAccessorClass = $constantsManager.getClass().getClassLoader().findClass('com.atlassian.jira.component.ComponentAccessor')) #set ($componentAccessorConstructor = $componentAccessorClass.getConstructor()) #set ($componentAccessor = $componentAccessorConstructor.newInstance()) ## Get comments #set($commentManager = $componentAccessor.getCommentManager().getComments($issue) ) ## Get Components #set ($componentManager = $componentAccessor.getProjectComponentManager().findComponentsByIssue($issue) ) ## Loop to fetch custom field values #foreach($customField in $customFields) #if($customField.name.equals("Service Now #")) #set ($snlabelValues = $customField.getValue($issue)) <b>Service Now No</b>: $snlabelValues #elseif($customField.name.equals("Salesforce Case #")) #set ($sflabelValues = $customField.getValue($issue)) <b>Salesforce Case No</b>: $sflabelValues #elseif($customField.name.equals("Business Units")) #set ($businessUnitValues = $customField.getValue($issue)) #foreach ($bUnits in $businessUnitValues) <b>Business Units</b>: $textUtils.htmlEncode($bUnits.getValue()) #end #end #end #end <title>$action.getText('release.notes.html.title', $project, $version) </title> <body> <table> <tr> <td> #foreach ($issueType in $issueTypes) #if($issueType.issues.size() > 0) <h2>$textUtils.htmlEncode($issueType.name)</h2> <ul> #foreach ($issue in $issueType.issues) <li>[<a xhref='$!appProps.getString("jira.baseurl")/browse/$issue.key'>$issue.key</a>] - $textUtils.htmlEncode($issue.summary) <b>Issue Type</b>: $issue.issueType.name <b>Description</b>: $issue.description <b>Resolution</b>: $issue.resolution.name <b>Status</b>: $issue.status.name <b>Fix Version/s</b>: $issue.fixVersions #getReleaseNoteComment($issue $customFieldManager)</li> #if ($commentManager) #foreach ($comment in $commentManager) <b>Comments</b>: $comment.body #end #end #if ($componentManager) #foreach($component in $componentManager) <b>Components</b>: $component.name #end #end #end </ul> #end #end </td> </tr> <tr> <td> <hr width="100%"> <a name="editarea"><h2>$action.getText('release.notes.edit.copy')</h2></a> <p>$action.getText('release.notes.description')<br></p> <textarea rows="40" cols="120"> $action.getText('release.notes.heading', $project, $version) #foreach ($issueType in $issueTypes) #if($issueType.issues.size() > 0) <h2>$textUtils.htmlEncode($issueType.name)</h2> <ul> #foreach ($issue in $issueType.issues) <li>[<a xhref='$!appProps.getString("jira.baseurl")/browse/$issue.key'>$issue.key</a>] - $textUtils.htmlEncode($issue.summary) <b>Issue Type</b>: $issue.issueType.name <b>Description</b>: $issue.description <b>Resolution</b>: $issue.resolution.name <b>Status</b>: $issue.status.name <b>Fix Version/s</b>: $issue.fixVersions #getReleaseNoteComment($issue $customFieldManager)</li> #if ($commentManager) #foreach ($comment in $commentManager) <b>Comments</b>: $comment.body #end #end #if ($componentManager) #foreach($component in $componentManager) <b>Components</b>: $component.name #end #end #end </ul> #end #end </textarea> </td> </tr> </table> </body>