The dynamic templates allow to render the message using data from the issue and issue screens(creation,editing, etc) that can be changed in real time. In templates you can use conditions, use Jira Java API or do some calculations before displaying the message. You can change the display parameters of the message - title, body, type, location. This functionality works in Jira Core/Software/Service Desk.
In previous versions of the application you could change message dynamically only using JavaScript. Many cases now can be done by using the dynamic templates(velocity templates (HTML + Java API) + real time render).
To enable templates you need to set Velocity render âOnâ in the field config.
Special variables will be available in the template for work with data. Links lead to Java doc with descriptions of available methods.
- $issue
- This variable contains the issue data stored in the database.
- This variable is not defined on the creation screen($context == âCREATEâ).
- $form
- JSON serialization of the form.
- Variable that contains information entered by the user on the screen (Create, Edit issue âŠ) without additional processing.
- The data in the variable is updated in real time.
- Variable value is entered data(without any validation).
- You can get values by the name of the property.
- $formIssue - đ„Recommended for use.
- The variable combines data from $issue and $form.
- Data from the screen($form) are in priority.
- The data from the screen($form) undergoes additional validation and processing. Invalid values ââreturn null.
- The data in the variable is updated in real time.
- $fieldDisplayConfig
- The variable contains information about the display of the message (message type, location, etc.).
- The message will be recreated when this information changes. JavaScript wonât run again.
- $context - Can have one of the following values:
- âCREATEâ - Issue create screen
- âEDITâ - Issue edit screen
- âTRANSITIONâ - Issue transition screens. Additional variables are accessed in this context:
- $transitionId - number
- $transitionName - string
- âVIEW_ISSUEâ - Issue view screen
- âCREATE_SDâ - Service desk create screen
- âVIEW_SDâ - Service desk view screen
- $currentUser
- The user who is viewing the message.
- $locale
- A Locale object represents a specific geographical, political, or cultural region of currentUser
- $language
- Returns the country/region code of currentUser. (String)
- $country
- Returns the country code of currentUser. (String)
- $timeZone
- Returns the timeZone of currentUser.
- $currentDateTime
- The current date time (server time zone).
- $nowInUserTimeZone
- The current date time (user time zone).
- $dateOfLastTransition
- The date of the last transition.
- $secAfterLastTransition
- How many seconds have passed since the last transition.
- $previousStatusId
- Number ID of previous status.
- $previousStatusName
- Name of previous status.
- $transitionId
- Number of current transition.
- Only available on transition screens.
- $transitionName
- Name of current transition.
- Only available on transition screens.
- $cfValues
- Utility object for getting custom field value from $issue and $formIssue.
- $links
- Utility object for getting issue links or linked issues.
- $jqlService
- Utility object for getting JQL results.
- linked Post: How to use linked issues and JQL results in Dynamic templates?
- $issueFieldRender
- Utility object for rendering issue fields values as HTML.
- $JSON
- Utility object for parse string to JSONObject.
- $ComponentAccessor
- Provides static methods for accessing JIRAâs managed components.
- $permissionHelper
- Tool for check permission.
- Example: $permissionHelper.hasPermission(âBROWSE_PROJECTSâ, $issue.reporter) - checking that the reporter of the issue has access to the project of the current issue.
- Permissions: ADD_COMMENTS, ADMINISTER_PROJECTS, ARCHIVE_ISSUES, ASSIGNABLE_USER, ASSIGN_ISSUES, BROWSE_ARCHIVE, BROWSE_PROJECTS, CLOSE_ISSUES, CREATE_ATTACHMENTS, CREATE_ISSUES, DELETE_ALL_ATTACHMENTS, DELETE_ALL_COMMENTS, DELETE_ALL_WORKLOGS, DELETE_ISSUES, DELETE_OWN_ATTACHMENTS, DELETE_OWN_COMMENTS, DELETE_OWN_WORKLOGS, EDIT_ALL_COMMENTS, EDIT_ALL_WORKLOGS, EDIT_ISSUES, EDIT_OWN_COMMENTS, EDIT_OWN_WORKLOGS, EDIT_SPRINT_NAME_AND_GOAL_PERMISSION, LINK_ISSUES, MANAGE_SPRINTS_PERMISSION, MANAGE_WATCHERS, MODIFY_REPORTER, MOVE_ISSUES, RESOLVE_ISSUES, RESTORE_ISSUES, SCHEDULE_ISSUES, SET_ISSUE_SECURITY, START_STOP_SPRINTS_PERMISSION, TRANSITION_ISSUES, VIEW_DEV_TOOLS, VIEW_READONLY_WORKFLOW, VIEW_VOTERS_AND_WATCHERS, WORK_ON_ISSUES
Parameters for demonstration
You can click Show Demo to test the display of a message.
You can see how your message will look like for the specified issue and execution context.
Conditions for displaying message and Permissions are not checked during this demonstration.
- Issue key - The message will be generated for this issue.
- Form data (JSON) - Text information from issue screen presented in JSON format.
- To collect test data:
- Open the issue screen(create, edit âŠ).
- Open your browser console.
- Execute the following code(Running JavaScript):
JSON.stringify(MESSAGE_FIELD_OBJECT.getDataFromDefaultForm (), undefined, 4)
- Paste its result in the box above. Except for the first and last quotes.
- To collect test data:
- Context - The message will be generated for this issue context.
- âCREATEâ - Issue create screen
- âEDITâ - Issue edit screen
- âTRANSITIONâ - Issue transition screens
- âVIEW_ISSUEâ - Issue view screen
- âCREATE_SDâ - Service desk create screen
- âVIEW_SDâ - Service desk view screen
You can see usage examples.