Hi, I use the Custom E-Mail Postfunction of Scriptrunner to send mails.
I include a customfield with a datepicker in the mail.
In the condition and configuration part I use this code
import com.atlassian.jira.component.ComponentAccessor
import java.time.format.DateTimeFormatter
import java.sql.Timestamp
def dateCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11209")
def dateTimestamp = issue.getCustomFieldValue(dateCF) as Timestamp
config.put('date', dateTimestamp.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))
return true
In the email template this
Hi, this is a test
<br /><br />
<% if (issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11209"))) out << "<b>Eintrittsdatum:</b> " << "${config['date']}" << "<br /><br />" %>
When the date is picked in the issue, everything works.
When the date is empty, the mail is never sent.
I think it is because the condition and configuration part has no check for emptiness and the DateTimeFormatter gives a back a failure or something.
How can I check for an empty field in this section and prevent, the problem?
Hi, I found a solution.
You need to catch the error of the dateTimestamp.toLocalDateTime() function.
try{//Your code}catch(Exception e){log.warn e}
In total it would look like this
import com.atlassian.jira.component.ComponentAccessor
import java.time.format.DateTimeFormatter
import java.sql.Timestamp
def dateCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11209")
def dateTimestamp = issue.getCustomFieldValue(dateCF) as Timestamptry{
config.put('date', dateTimestamp.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))catch(Exception e){log.warn e}
return true
l
 
 
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.