Groovy Script
Code example:
def parameters = [:] parameters["assignee"] = issue.assignee parameters["reporter"] = issue.reporter def userManager = ComponentAccessor.getUserManager() parameters["userDisplayName"] = userManager.getUserByName("someUserName").getDisplayName() def cf = customFieldManager.getCustomFieldObject("customfield_xxxxx") def price = issue.getCustomFieldValue(cf) parameters["price"] = (null != price) ? price : "No price defined" return parameters
Velocity Engine
User
assignee = $issue.assignee or {{issue.assignee}}
reporter = $issue.reporter or {{issue.reporter}}
displayName = $user.displayName
userDisplayName = $ComponentAccessor.getUserManager().getUserByName("someUser").getDisplayName()
Date
Issue date fields:
updated = $issue.updated
created = $issue.created
Formatted date:
formattedDate = $DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format($issue.created)
Custom Field Values
productName = $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11100'))
price = $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11102'))
Utils
- jsonEscapedString = $Utils.jsonEscape($issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_12500')))
Comment
Getting a comment which has passed through the transition:
- comment = $comment
Field Changes in Transition
$issue.get..
methods might return the old or new values within a transition depending on the location of the post function.
Assume that we have a transition which uses a transition screen in which customfield_10123 can be changed.
- If the REST Service Caller post function is BEFORE the "Update change history for an issue and store the issue in the database." post function, then
$issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123'))
call would return the old value. - If the REST Service Caller post function is AFTER the "Update change history for an issue and store the issue in the database." post function, then
$issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123'))
call would return the new value.
But, what if we need both values?
You can use transientIssue
for the updated fields within the transition instead of issue
- productName = $transientIssue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123'))
Line Breaks
You can remove line breaks with the replaceAll() method:
- description = $issue.description.replaceAll("\n", "")
Render Options
You can render parameters in HTML or Plain Text:
- HTML render → $wikiUtils.wikiToHtml($comment)
- Plain Text render → $wikiUtils.wikiToText($comment)
EscapeTool
You can escape parameters with the EscapeTool, for example:
- issueSummary = $escape.html($issue.summary)
The EscapeTool has lots of useful methods. You can find all of the methods here.
MathTool
You can convert parameters with the MathTool, for example:
- price = $mathUtils.toInteger($issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11100')))
The MathTool has lots of useful methods. You can find all of the methods here.
Empty/Null values
Simply add ! after $ sign if the result can be empty or null. Otherwise, it will display the command as is (e.g. $issue.assignee).
Null safe usage: $!issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_xx')) .