Scripted Field - Date appearing as Date Time. (Field pulls date from parent)

Duane Cronkite January 27, 2021

I am using this script and the date from the parent is returning with blank Time. I want just the date to appear.

Using "Date" template on script and Date Time on the searcher I got the results I wanted of just the date only but... the date was one day off.

Currently I have it set to "Text field" template on script and free text on the searcher and its displaying date as "2021-01-04 00:00:00.0"

Thanks in advance for the help!

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

if (issue.isSubTask())
{
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Received Date");

if (field != null)
{
return issue.getParentObject().getCustomFieldValue(field);
}
}

return null;

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 27, 2021

Hi @Duane Cronkite I guess value of the field is of java.util.Date type. So you just need to format it in "return" statement. So you have to add following lines to your source code:

  1. import java.text.SimpleDateFormat
  2. import java.util.Date
  3. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd")
  4. return formatter.format(issue.getParentObject().getCustomFieldValue(field))

Suggest an answer

Log in or Sign up to answer