Custom mail post function due Date not formatting correctly

We use a script workflow function from Script Runner to send a custom mail which is working as expected. In the mail body we want to display the due Date with the right formatting. When using the preview button, the date is displayed but in the mail the field is empty.


Can you help me find what is wrong? I tried the following to achieve the expected result:

  1.  $issue.dueDate
    1. Working in Preview = 2015-12-08 00:00:00.0
    2. Working in Mail = 2015-12-08 00:00:00.0
  2. ${issue.dueDate.format('MM.dd.yyyy')}

    1. Working in Preview = 12.08.2015

    2. Not Working in actual Mail = Field is empty

       

1 answer

This widget could not be displayed.
Vasiliy Zverev Community Champion Dec 16, 2015

Try using SimpeDateFormat class to format Date output

Thanks for your reply. Could you provide an example on how to include SimpeDateFormat class? I'm fairly new with this kind of scripts.

Vasiliy Zverev Community Champion Dec 16, 2015

import this: import java.text.SimpleDateFormat; set disarable format like: SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd"); use it simpleDateFormat.format(someValue); Detailed documentation you can get here: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

I tried the suggested method, but it looks like it is not applicable in this case, since we use the scriptrunner pre-configure script workflow post-function "Send a custom E-Mail".

 

When I paste the import into any of the available fields it wills just display the pasted import text.

Vasiliy Zverev Community Champion Jan 18, 2016

If you have some code you should place all import statements on the top of code, before any useage, and then place code.

Namely it should get something like this

*****

import ......

import java.text.SimpleDateFormat;

import..


//Declare the variable:

 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd")

//and then call this variable to formate date where you need.

simpleDateFormat.format(someValue)

According to the description of the "Email Template" and "Subject Template" field of the "Send a custom email" script this is not allowed. The description says: "Can be plain text or use the GStringTemplateEngine."

When I try your code the preview button produces the following output:

 
import java.text.SimpleDateFormat;
//Declare the variable:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd")
//and then call this variable to formate date where you need.
simpleDateFormat.format(2015-12-08 00:00:00.0)

For reference, I'm using the script described here: https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts

 

 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

286 views 5 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you