Hello,
i have a big problem. I need to change the email template in jira datacenter.
What i need is, that on every mail the mail subject should include a custom field value.
This solution works for the mail templates without batching notification:
issueupdate.vm
#set($customFieldManager = $componentManager.getCustomFieldManager())
#set($serialnumberField = $customFieldManager.getCustomFieldObject("customfield_10xxx"))
#set($serialnumber = $issue.getCustomFieldValue($serialnumberField ))
#if ($serialnumber)
($issue.key) [$serialnumber] $issue.summary
#else
($issue.key) $issue.summary
#end
#set($customFieldManager = $componentManager.getCustomFieldManager())
#set($serialnumberField = $customFieldManager.getCustomFieldObject("customfield_10xxx"))
#set($serialnumber = $issue.getCustomFieldValue($serialnumberField ))
#if ($serialnumber)
#set($headersum = "[$serialnumber] " + "$header.issueSummary" + " with SNR")
$i18n.getText('issue.update.batch.mail.subject', [$header.issueKey, $headersum])
#else
#set($withoutSN = "$header.issueSummary" + " wihtout SNR")
$i18n.getText('issue.update.batch.mail.subject', [$header.issueKey, $withoutSN ])
#end
The var serialnumber is always empty / null and i have no clue how to solve that issue.
I hope you can help me.
Thx
Hi @Fabian
As far as I remember in batched notifications, it is not rendered with an $issue in the velocity context. So it always returns null. You will need to fetch the issue and get the customfield value from the issue which may not be the most performant way.
I am not 100% sure but I think you can get the issuekey from the $header (it is best to check it out) and the code will be like the below
#set($customFieldManager = $componentManager.getCustomFieldManager())
#set($issueManager = $componentManager.getIssueManager())
#set($serialnumberField = $customFieldManager.getCustomFieldObject("customfield_10xxx"))
#set($theIssue = $issueManager.getIssueObject($header.issueKey))
#set($serialnumber = $theIssue.getCustomFieldValue($serialnumberField))
... the rest of your code
Hi @Tuncay Senturk _Snapbytes_
here is a solution that works for me.
Maybe it also helps other people too.
First the field customfield_xxxxx need to be registered with the batchers context:
POST /rest/inform-batchers/1.0/customfields?id=customfield_xxxxx
After you registered your field you can use it in your batch templates:
#set($cf = $customFields.get('customfield_xxxxx'))
#if ($cf && $cf.value)
#set($headerSummary = "[$cf.value] $header.issueSummary")
#else
#set($headerSummary = "$header.issueSummary")
#end
$i18n.getText('issue.update.batch.mail.subject', [$header.issueKey, $headerSummary])
Important to know:
This code example is only for batch notifications.
For normal notifications you can already use the customfields without registrations
#set($customFieldManager = $componentManager.getCustomFieldManager())
#set($customField = $customFieldManager.getCustomFieldObject("customfield_xxxxx"))
#set($customFieldValue = $issue.getCustomFieldValue($customField ))
#if ($seriennummer)
...
Kind regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.