Forums

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

[Scriptrunner] Send Custom E-Mail: Mail not send when datefield is empty

Lars Swart
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.
September 23, 2021

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?

1 answer

1 accepted

0 votes
Answer accepted
Lars Swart
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.
September 24, 2021

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 Timestamp

try{
config.put('date', dateTimestamp.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))
catch(Exception e){ 

  log.warn e

}


return true

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.8
TAGS
AUG Leaders

Atlassian Community Events