Dynamic templates - Examples

Examples of using variables that are available for use in dynamic templates.

Java doc for Message field.

You can see the official user guide for velocity here.

Common

How to set the value of variable?

#set( $foo = "Velocity" )
Hello $foo World!

Conditionals

#set( $foo = "Velocity" )

Hello 
#if( $foo )
    <strong>Velocity!</strong>
#end
World!

Loops

<ul>
#foreach( $product in $allProducts )
    <li>$product</li>
#end
</ul>

Comments

## This is a single line comment.  

#*
  Thus begins a multi-line comment. Online visitors won't
  see this text because the Velocity Templating Engine will
  ignore it.
*#   

Getting data from the screens

How to use $form? Get raw data from issue screen.

$form.summary <br>
$form.customfield_10400

How to use $formIssue? Get valid data from the issue screen.

see Java doc $formIssue

$formIssue.summary <br>
$formIssue.priority.name <br>
#if($formIssue.assignee)
    $formIssue.assignee.displayName<br>
#else
    Unassigned<br>
#end

How to use $cfValues? How to get the value of a custom field for an $issue?

see Java doc $cfValues

$cfValues.get(10100)<br>
$cfValues.get("customfield_10100")<br>
$cfValues.get("Custom field name")<br>

$cfValues.getOrDefault(10100, "Default value")<br>
$cfValues.getOrDefault("customfield_10100", 123)<br>
$cfValues.getOrDefault("Custom field name", $issue.assignee)<br>

##use for get value for linked issue
$cfValues.get($linkedIssue, 10100)<br>
$cfValues.getOrDefault($linkedIssue, "customfield_10100", "Default value")<br>
$cfValues.getOrDefault($linkedIssue, "Custom field name", 123)<br>

How to get the value of a custom field for an $formIssue?

$cfValues.getFromForm(10100)<br>
$cfValues.getFromForm("customfield_10100")<br>
$cfValues.getFromForm("Custom field name")<br>

$cfValues.getFromFormOrDefault(10100, "Default value")<br>
$cfValues.getFromFormOrDefault("customfield_10100", 123)<br>
$cfValues.getFromFormOrDefault("Custom field name", $issue.assignee)<br>

How to use $fieldDisplayConfig? How to change the display of a message?

see Java doc $fieldDisplayConfig

$fieldDisplayConfig.setAsFlag(true) ## true, false
$fieldDisplayConfig.setMessageType("info") ## "info", "error", "success", "warning", "change", "SIMPLE_VIEW"
$fieldDisplayConfig.setTitle("New title") 
$fieldDisplayConfig.setShowForFieldId("summary") ## "customfield_10100"
$fieldDisplayConfig.setInsert("before") ## "append", "prepend", "before", "after" 
$fieldDisplayConfig.setHidden(true)

How to hide a message?

see Java doc $fieldDisplayConfig

#set ($optionCustomFieldValue = $cfValues.getFromForm("Option custom field name"))
#if($optionCustomFieldValue.value == "option 1" )
    $fieldDisplayConfig.setTitle("New title for option 1")
    Body text for option 1<br> 
#elseif($optionCustomFieldValue.value == "option 2" )
    #set ($titleForOption2 = "New title for " + $optionCustomFieldValue.value)
       $fieldDisplayConfig.setTitle($titleForOption2)
       Body text for option 2<br>
#else
    $fieldDisplayConfig.setHidden(true)##hide
#end

How to change message colour?

see Java doc $fieldDisplayConfig

dynamic template random message colors.gif

$fieldDisplayConfig.setMessageType("custom") ##require for custom colors
#set($r = $mathTool.random(0,255))
#set($g = $mathTool.random(0,255))
#set($b = $mathTool.random(0,255))
$fieldDisplayConfig.setBackgroundColor("rgb($r,$g,$b)") ## color as hex "#FFFFFF", "rgb(255,255,255)", "rgba(255,255,255, 1)"
#set($r = $mathTool.random(0,255))
#set($g = $mathTool.random(0,255))
#set($b = $mathTool.random(0,255))
$fieldDisplayConfig.setTextColor("rgb($r,$g,$b)")
#set($r = $mathTool.random(0,255))
#set($g = $mathTool.random(0,255))
#set($b = $mathTool.random(0,255))
$fieldDisplayConfig.setIconColor("rgb($r,$g,$b)")


$issue.key: $issue.summary

How to use $context, $transitionId and $transitionName?

#if($context == "TRANSITION")
	is transitionId 31 ? #if($transitionId == 31) Yes #else No #end <br>
	is transitionName "In Progress" ? #if($transitionName == "In Progress") Yes #else No #end<br>
#end

How to use and check linked issues?

see Java doc $links

#set ($blockedIssues = $links.getOutwardIssues("blocked"))
#if($blockedIssues.size() > 0)
    #foreach($blockedIssue in $blockedIssues)
        $blockedIssue.status.name $cfValues.getOrDefault($blockedIssue, "developer custom field", "hasn't developer")<br>
    #end
#end

Show message for “description” and “assignee” depending on the priority.

dynamic template demo.gif

#if($formIssue.priority.name == "Blocker")
	$fieldDisplayConfig.setMessageType("error")
	#if(!$formIssue.description || $formIssue.description.isEmpty())
		$fieldDisplayConfig.setShowForFieldId("description")
		State the reason for the Blocker priority.
	#elseif(!$formIssue.assignee)
		$fieldDisplayConfig.setShowForFieldId("assignee")
		Indicate the responsible employee
	#else
	  $fieldDisplayConfig.setHidden(true)
	#end
#elseif($formIssue.priority.name == "High")
	$fieldDisplayConfig.setMessageType("warning")
	#if($formIssue.description.isEmpty())
		$fieldDisplayConfig.setShowForFieldId("description")
		State the reason for the High priority.
	#else
	  	  $fieldDisplayConfig.setHidden(true)
	#end
#elseif($formIssue.priority.name == "Medium" || $formIssue.priority.name == "Low")
	$fieldDisplayConfig.setHidden(true)
#end

How to use JQL in message? How to use $jqlService?

see Java doc $jqlService

$jqlService.getIssuesByJQL("priority = $formIssue.priority.name ORDER BY Key DESC", 10)

You can use current issue in jql for conditions:

#if($jqlService.getIssueCountByJQL("key = $issue.key and updated < startOfDay(-2)") > 0)
    The problem has not been updated for more than two days.
#end

How to show fields for issues by JQL in message? How to use $issueFieldRender?

see Java doc $issueFieldRender

$issueFieldRender.getAsTableHtml( 
	$jqlService.getIssuesByJQL("priority = $formIssue.priority.name ORDER BY Key DESC", 5), 
	"issue key", "Priority", "Assignee", "customfield_10110", "Product categorization", "10110"
	)

Check priority

Check priority.gif

  #if($formIssue.priority.name == "Blocker")
  $fieldDisplayConfig.setMessageType("error")
  
      State the reason for the Blocker priority. ##Message text
  #elseif($formIssue.priority.name == "High")
      $fieldDisplayConfig.setMessageType("warning")
    
      State the reason for the High priority. ##Message text
  #end

Check components

  #foreach($component in $formIssue.components)
     #if($component.name == "Test component")

        You have selected a test component ##Message text
     #end
  #end

Validate summary

Validate summary.gif

  #if($formIssue.summary.contains("PROJECTKEY"))
     message contains PROJECTKEY<br> ##Message text
  #end

  #if($formIssue.summary.matches("(.*)PROJECTKEY(.*)"))
     message contains PROJECTKEY (cheked by regex)<br> ##Message text
  #end

  #if($formIssue.summary.length() < 10)
     Short summary<br> ##Message text
  #end

Check description and User Picker (single user)

description-and-user-picker(single).gif

  #if(!$form.description || $form.description.trim() == "" || !$cfValues.getFromForm("User Picker (single user)"))
     You need to set data in the system description field and specify the user in the custom field "User Picker (single user)" ##Message text
  #end

Check number custom field

Check number custom field.gif

  #if($cfValues.getFromForm("Number") > 10)
     number > 10 ##Message text
  #end

Check option from custom select field(checkbox or radio)

Check option from custom select field(checkbox or radio).gif

  #if($cfValues.getFromForm("Radio").optionId == 10102)
     Selected option with Id 10102<br> ##Message text
  #end

  #if($cfValues.getFromForm("Single select field").name == "yes")
      Selected option with name  "yes"<br> ##Message text
  #end

  #if($form.customfield_10202.indexOf("10301") > -1)
     "Select List (multiple choices)" contains otpion with id 10301(option2) ##Message text
  #end

Rest API
Custom colors and HTML
JiBrok message field Message field
JiBrok time in status Time in status | SLA | Timer | Stopwatch
Tutorials
Settings
Work calendars
Time in status
Timers and Stopwatches
Stopwatch
Timer
Additional functions
Issue panels
Reports
Field Helpers
Other fields
API
Reference information