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 screen/issue

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 issue type?

#if($formIssue.issueType.name == 'Task')
     message for 'Task'
#elseif($formIssue.issueType.name == 'Bug')
     message for 'Bug'
#end

or

#if($formIssue.issueType.id == 10000)
     message for 'Task'
#elseif($formIssue.issueType.id == 10001)
     message for 'Bug'
#end

or

#if($issue.issueType.name == 'Task')
     message for 'Task'
#elseif($issue.issueType.name == 'Bug')
     message for 'Bug'
#end

($issue - this variable is not defined on the creation screen)

How to use issue status?

#if($issue.status.name == 'To Do')
     message for 'To Do' status
#elseif($issue.status.name == 'In progress')
     message for 'In progress' status
#end

or

#if($issue.status.id == 10000)
     message for 'To Do' status
#elseif($issue.status.id == 10001)
     message for 'In progress' status
#end

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?

$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?

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

How to show fields from linked issues(also on Service Desk Portal)? How to use $issueFieldRender?

see Java doc $issueFieldRender

This example uses a different our plugin: Display linked issues 1) Create and configure field “Linked issues”:

linked-issues-config.png

2) After creating the “linked issues” field, you can display it in the message body:

$issueFieldRender.getFieldValueHtml($issue,"customfield_10101")

3) Result:

render-another-field-1.png
render-another-field-2.png

How to display the date in the correct format with $issueFieldRender?

see Java doc $issueFieldRender

$issueFieldRender.dateFormat($formIssue.created, "dd-MMM-yyy HH:mm")
<br/>
$issueFieldRender.dateFormat($formIssue.created, "dd-MM-yyyy")

Result: dateformat.png

How to show the multiline value of a text field with $issueFieldRender?

see Java doc $issueFieldRender

<b>original value of issueForm field "description":</b><br/>
$formIssue.description
<br/>
<b>After formating for better look:</b><br/>
$issueFieldRender.replaceNewlineCharactersForHtml($formIssue.description)
<br/
<br/>
<b>Original value of issueForm custom field "Text Field (multi-line)":</b><br/> ## customfield_10102
$cfValues.getFromForm("customfield_10102")
<br/>
<br/>
<b>After formating for better look:</b><br/>
$issueFieldRender.replaceNewlineCharactersForHtml($cfValues.getFromForm("Text Field (multi-line)"))

<hr/>

<b>HTML render available for any field of issue:</b><br/>
<b>Description:</b><br/>
$issueFieldRender.getFieldValueHtml($issue, "description")
<br/>
<b>Text Field (multi-line):</b><br/>
$issueFieldRender.getFieldValueHtml($issue, "customfield_10102")

Result: replaceNewlineCharactersForHtml.png

Get parent issue

$formIssue.parentObject.key
$issue.parentObject.key

#if($formIssue.parentObject)
  $cfValues.get($formIssue.parentObject, "Impact").value ## impact - custom select field
#end

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

Check how long ago the transition was made. Show message after transition. (How to use $secAfterLastTransition)

  $fieldDisplayConfig.setHidden(true)##hide message by default (Including cases when there were no transitions yet.)

  #if($secAfterLastTransition && $secAfterLastTransition < 1*60)##We check that less than 1 minute has passed since the last transition (the time is indicated as a number of seconds)
	$fieldDisplayConfig.setHidden(false)## Show a message if the transition was not long ago. (< 1 min ago)
	
	##message edit here
	data:<br>
	$secAfterLastTransition<br>
	$previousStatusId <br>
	$previousStatusName <br>

  #end

Display messages in the user’s language. (Multi-language messages. How to use $language?)

  #if($language == "es")
      mensaje en español<br>
      lĂ­nea 2
  #elseif($language == "fr")
      message en français<br>
      ligne 2
  #else
      message in english<br>
      line 2<br>
  #end

How to work with cascade select field?

  1 - $cfValues.getFromForm(10101)<br>
  2 - $cfValues.getFromForm("customfield_10101")<br>
  3 - $cfValues.getFromForm("customfield_10101").getOptionId()<br>
  4 - $cfValues.getFromForm("customfield_10101").getValue()<br>
  5 - $cfValues.getFromForm("customfield_10101:1")<br>
  6 - $cfValues.getFromForm("customfield_10101:1").getOptionId()<br>
  7 - $cfValues.getFromForm("customfield_10101:1").getValue()<br>
  8 - $cfValues.getFromForm("cascade test")<br>
  9 - $cfValues.getFromForm("cascade test:1")<br>
  <br>
  10 - $cfValues.getFromFormOrDefault("customfield_10101", "defaultOption")<br>
  11 - $cfValues.getFromFormOrDefault("customfield_10101:1", "defaultOption")<br>
  12 - $cfValues.getFromFormOrDefault("cascade test", "defaultOption")<br>
  13 - $cfValues.getFromFormOrDefault("cascade test:1", "defaultOption")<br>
  14 - $cfValues.getFromFormOrDefault("cascade test1:1", "defaultOption")<br>
  15 - $cfValues.getFromFormOrDefault("cascade test1:12", "defaultOption")<br>
  <br>
  16 - $cfValues.get(10101)<br>
  17 - $cfValues.get(10101).get(null)<br>
  18 - $cfValues.get(10101).get("1")<br>
  19 - $cfValues.get("customfield_10101")<br>
  20 - $cfValues.get("customfield_10101").get(null).getValue()<br>
  21 - $cfValues.get("customfield_10101").get("1").getValue()<br>
  22 - $cfValues.get("customfield_10101").get(null).getOptionId()<br>
  23 - $cfValues.get("customfield_10101").get("1").getOptionId()<br>
  <br>
  24 - $cfValues.getOrDefault("customfield_10101", "defaultValue")<br>
  25 - $cfValues.getOrDefault("customfield_10101", 10000).get(null).getOptionId()<br>
  26 - $cfValues.getOrDefault("customfield_10101", 10000).get("1").getOptionId()<br>
  27 - $cfValues.getOrDefault("cascade test", "defaultOption")<br>
  28 - $cfValues.getOrDefault("cascade test", "defaultOption").get(null).getValue()<br>
  29 - $cfValues.getOrDefault("cascade test", "defaultOption").get("1").getValue()<br>
  30 - $cfValues.getOrDefault("cascade test123123", "defaultOption")<br>
  31 - $cfValues.getOrDefault("cascade test1:12", 10000)<br>

Issue create screen: Cascade select - Create

Other issue screens: Cascade select - edit - view

Conditions:

  #if($cfValues.getFromForm(10101) == "parent1")
     message<br>
  #end
  #if($cfValues.getOrDefault("cascade test", "defaultOption").get("1").getValue() == "child1")
     message2<br>
  #end
  #if($cfValues.getFromForm("customfield_10101").getOptionId() == 10000)
     message3<br>
  #end

How to use $insightService?

see Java doc $insightService

  $insightService.findObjects("key = TEST-1", 1) ##find (1) object by IQL
  <br>
  $insightService.findObjects("key = TEST-1", 1).get(0).getObjectAttributeBeans() ##get all attribute's ids from first object
  <br>
  $insightService.getIQLAsTableHtml("key = TEST-1", 1, "Key", "Created", "Name", "Updated") ## use attribute's names
  <br>
  $insightService.getIQLAsTableHtml("key = TEST-1", 1, 3, 2, 1, 4) ## use attribute's ids
  <br>
  $insightService.getIQLAsTableHtml("key = TEST-1", 1, 3, 2, 1, 4) ## use attribute's ids
  <br>
  search by objectId:<br>
  $insightService.getIQLAsTableHtml("objectId = 1", 1, "Key", "Created", "Name", "Updated") ## search by objectId and display attributes by names
  <br>
  Work with insight object custom field:<br>
  #if($cfValues.getFromForm(10200))#insight custom field. If value isn't empty IQL will use id from insight object(value).
     $insightService.getIQLAsTableHtml("objectId = $cfValues.getFromForm(10200).id", 1, "Key", "Created", "Name", "Updated") ## search by objectId and display attributes by names
  #end

How to use $cast?

see Java doc $cast

  #set ($messages = {
      "Story" : {
          10000: "Message for story with option id 10000",
          10001: "Message for story with option id 10001"
      } ,
       "Task" : {
          10000: "Message for task with option id 10000",
          10001: "Message for task with option id 10001"
       }
  })
  
  
  #set($message = $messages.get($formIssue.issueType.name).get(
  $cast.toInteger($cfValues.getFromForm("customfield_10200").optionId)
  ))
  
  #if($message)
     $message
  #else
     $fieldDisplayConfig.setHidden(true)##hide
  #end

Example scenarios

Project managers want a warning message on the form if the issue priority is High.

  #if($issue.getPriorityObject().name == "High")
  <b style="color:red;">Warning: the issue priority is High!</b>
  #else
  <p>Normal priority. Work as usual.</p>
  #end
  #if($issue.assignee)
    <p>Assignee: $issue.assignee.displayName</p>
    <p>Email: $issue.assignee.emailAddress</p>
  
     #set($slackLink = $issue.assignee.getPropertyValue("slackLink"))
     #if($slackLink)
        <p>Slack: <a href="$slackLink" target="_blank">$slackLink</a></p>
     #else
        <p>No Slack link specified.</p>
     #end
  #else
    <p><i>No assignee</i></p>
  #end

Different issue types (Bug, Task, etc.) require different message formats.

  #set($typeName = $issue.issueTypeObject.name)
  
  #if($typeName == "Bug")
  <p>Important for bugs: ensure reproducible steps are provided.</p>
  #elseif($typeName == "Task")
  <p>Task: verify deadlines and resources.</p>
  #else
  <p>Issue type: $typeName. No extra instructions required.</p>
  #end

Suppose the issue can have components like “UI/UX”, “Backend”, “Mobile”. Depending on the chosen component, show which team is responsible.

  #set($components = $issue.getComponents())
  #if($components && $components.size() > 0)
    <p>Selected components:</p>
    <ul>
      #foreach($comp in $components)
        <li>
          $comp.name
          #if($comp.name == "UI/UX")
            - The design team is responsible for mockup review
          #elseif($comp.name == "Backend")
            - The backend team handles microservices
          #elseif($comp.name == "Mobile")
            - The mobile team checks compatibility with iOS/Android
          #end
        </li>
      #end
    </ul>
  #else
    <p style="color:orange;">No components selected. Please specify at least one!</p>
  #end

If the Due Date has passed, show a red warning.

  #set($dueDate = $issue.getDueDate())
  #if($dueDate && $dueDate.before($actionDate))
  <p>The issue is overdue! Date: $dueDate</p>
  #else
  <p>The issue is on schedule or no due date is set.</p>
  #end

If no Fix Version is set, show a warning.

  #set($fixVersions = $issue.getFixVersions())
  #if($fixVersions && $fixVersions.size() > 0)
  <p>Planned for versions:
    #foreach($ver in $fixVersions)
      <strong>$ver.name</strong><br/>
    #end
  </p>
  #else
  <p>No version selected. Please specify the release.</p>
  #end

If the issue type is “Bug”, display a note about reproducible steps; if it’s “Story”, mention acceptance criteria, etc.

  #set($type = $issue.issueTypeObject.name)
  #if($type == "Bug")
  <p>Please provide reproducible steps.</p>
  #elseif($type == "Story")
  <p>Please describe the expected result and acceptance criteria.</p>
  #else
  <p>No special requirements for type: $type</p>
  #end

If the value > 100000, show an alert.

  #set($budgetField = $cfValues.getFromForm("Budget")))
  #if($budgetField && $budgetField > 100000)
  <p style="color:red;">Warning! Budget exceeded 100,000. Additional check required.</p>
  #else
  <p>Budget is within acceptable limits.</p>
  #end

If the user selects the “UI/UX” component, show a design reminder; if “Backend”, show a microservices reminder.

  #set($componentList = $issue.getComponents())
  #set($hasUIUX = false)
  #set($hasBackend = false)
  
  #foreach($comp in $componentList)
     #if($comp.name == "UI/UX")
        #set($hasUIUX = true)
     #elseif($comp.name == "Backend")
        #set($hasBackend = true)
     #end
  #end
  
  #if($hasUIUX)
  <p style="color:purple;">Please coordinate mockups with the design team.</p>
  #end
  #if($hasBackend)
  <p style="color:green;">Check compatibility with the microservices architecture.</p>
  #end
  #if(!$hasUIUX && !$hasBackend)
  <p>No specific components selected, proceeding under standard workflow.</p>
  #end
  #set($attachments = $issue.getAttachments())
  #if($attachments && $attachments.size() > 0)
     Attachments in this issue:
     #foreach($attachment in $attachments)
        #if($attachment.filename.endsWith(".xlsx"))
        - Excel File: <a href="$attachment.url" target="_blank">$attachment.filename</a>
        #elseif($attachment.filename.endsWith(".pdf"))
        - PDF Document: <a href="$attachment.url" target="_blank">$attachment.filename</a>
        #else
        - File: <a href="$attachment.url" target="_blank">$attachment.filename</a>
        #end
     #end
  #else
     No attachments found.
  #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
JiBrok Switch to User + Delegating SU (Jira) Switch to User + Delegating SU (Jira)
JiBrok time in status Time in status for Jira Cloud
Work calendars
Time in status fields
Issue panels
Reports
Service tools
Reference information
JiBrok Calculated fields Calculated fields (JBCF)
JiBrok Calculated fields Calculated fields (JBCF) for Jira Cloud
JBCF fields
Service tools
JiBrok Timer Timer field | SLA for Jira Cloud
Work calendars
Timer fields
Issue panels
Service tools
JiBrok Stopwatch Stopwatch for Jira Cloud
Work calendars
Stopwatch fields
Issue panels
Service tools
JiBrok Time between dates Time between dates for Jira Cloud
Time between dates fields
JiBrok Fields panel for Jira Service Management (JSM) Fields panel for Jira Service Management (JSM)
JiBrok Display Linked Issues Display Linked Issues
User helper for JiBrok cloud apps User helper for JiBrok cloud apps