Create URLs from Custom Fields with Comma-Separated Ids

Introduction

We needed a way to link to external bug trackers via a custom field. Perhaps the most appropriate advance would have been to write a Custom Field Plugin, but I found a solution which is much simpler and perhaps might also serve your purposes.

Installation

This has been tried with the WAR-version of JIRA 3.5.2:

  1. Copy webapp/WEB-INF/classes/templates/plugins/fields/view/view-basictext.vm to edit-webapp/WEB-INF/classes/templates/plugins/fields/view/
  2. Change the velocity macro to something like:
    view-basictext.vm
    #macro( renderUrls $urlIdPrefix $urlIdPostfix $idList )
    	<ul>
    	#foreach( $id in $idList )
    		#set($trimmedId = $id.trim())
    		#set($url="${urlIdPrefix}${trimmedId}${urlIdPostfix}")
    		<li><a href="${url}" target="_blank">${trimmedId}</a></li>
    	#end
    	</ul>
    #end
    
    #macro( renderBugtracker1Ids $idString )
    	#set($idList=$idString.split("[,;]"))
    	#renderUrls("http://my-bugtracker/?id=" "" $idList)
    #end
    
    #macro( renderBugtracker2Ids $idString )
    	#set($idList=$idString.split("[,;]"))
    	#renderUrls("http://another-bugtracker/?id=" "&template=show" $idList)
    #end
    
    #if ($value)
    	#if (${displayParameters.excel_view})
    		$textutils.br($textutils.htmlEncode($!value.toString(), false))
    	#else
    		#set($name=$customField.getName())
    		#set($strValue=$!value.toString())
    		#if ($name)
    			#set($ignoreCaseName=$name.toLowerCase())
    			#if ($ignoreCaseName.indexOf("bugtracker1") != -1)
    				#renderBugtrackerIds($strValue)
    			#elseif ($ignoreCaseName.indexOf("bugtracker2") != -1)
    				#renderRequesttrackerIds($strValue)
    			#else
    				$strValue
    			#end
    		#else
    			$strValue
    		#end
    	#end
    #end
  3. As you might guess you have to change the field names and URLs to something of your choice.
  4. Build the WAR and deploy it.
  5. Now you just have to create a custom field where the name contains bugtracker1 oder bugtracker2 and rendering will work

Labels

 
(None)