Hi all,
I am desperately searching for a way to query the due date of an issue in a HTML body within a post function for sending our an email with JEMH plugin in jira.
When I am trying $!issue.getCustomFieldValue("customfield_duedate") I receive an error message while testing:
Test Postfunction message failed to send
Unhandled error: Failed to render template #0
How can I get this field? And even more,. how can I add two days to this date to be disyplayed in the email body?
Thanks a lot in advance
BR
Franzi
In order to use the "test" button at the top of the post-function screen of JEMH, you first need to have a template that renders correctly. Ensure that a valid issue key is entered in the "preview context" box. Then, scroll down to your "custom content" where your custom velocity template is. There will be a small blue button that gives you a rendered preview of your template.
The standard "due date" field is not a custom field but a normal jira field. It can be accessed via $issue.getDueDate() however this appears to be unusable due to its class (Timestamp) being restricted for some reason... Atlassian velocity security measures it appears.
Anyway, there is a longer way which allows you to manipulate the due date with the more modern LocalDateTime class (https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html).
## first we get the original due date object and convert to string
#set ($orig = $issue.getDueDate())
#set ($str = $dateFormatter.format($orig))
## then we get a date formatter - you may need to change the below format
## if yours if different
#set ($fmt = $jemhDateUtils.getFormatter("dd/MMM/yy hh:mm a"))
#set ($new = $jemhDateUtils.createLocalDateTime().parse($str, $fmt))
## you now have a LocalDateTime object that can be easily adjusted
$new.plusDays(2)
Hello,
thanks for your answer! So, what I understand is, that I should enter the following in the HTML Body:
($orig = $issue.getDueDate())
($str = $dateFormatter.format($orig))
($fmt = $jemhDateUtils.getFormatter("dd/MM/yyyy"))
($new = $jemhDateUtils.createLocalDateTime().parse($str, $fmt))
$new.plusDays(2)
I tried so but it gave me this in the email:
($orig = 2021-03-29 00:00:00.0)
($str = 18.03.2021 07:36)
($fmt = Value(DayOfMonth,2)'/'Value(MonthOfYear,2)'/'Value(YearOfEra,4,19,EXCEEDS_PAD))
($new = $jemhDateUtils.createLocalDateTime().parse($str, $fmt))
$new.plusDays(2)
So it worked half but this formatter seems not working.
BR
Franzi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to use #set for setting variables. See my previous code example. This code is called a Velocity template. More information on using Apache Velocity can be found here: https://velocity.apache.org/engine/1.7/user-guide.html
#set( $myVar = "hello")
$myVar
The above would result in "hello" being rendered.
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.