Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Query the due date in Velocity (email HTML)

Franzi Joseph March 16, 2021

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

1 answer

1 accepted

1 vote
Answer accepted
Mike Harrison
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2021 edited

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)
Franzi Joseph March 18, 2021

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

Mike Harrison
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 25, 2021 edited

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.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events