Custom field based on Priority + created date

Hello all,

I am looking to create a custom field that will be based on create date plus priority. This field will be mostly used for reporting purposes on columns. I found few examples on creating a listener or adding a workflow create post function. Would it be possible just to go with a custom field, rather then creating something on a workflow.

Example would be:

Create date + 1d if it's a P1, +2d if it's a P2, and +3d if it's a P3.


Any suggestions would be greatly appreciated.


2 answers

1 accepted

Hi DF,

I have attached some example code of how you can use to create a scripted field using a Text Field template that will take the created date and add a number of days to it based on the priority. This field returns a string value of the date which you may find easier to use for reporting purposes.

import com.atlassian.jira.issue.Issue
import org.apache.commons.lang.time.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Date.*;

// Get the Jira issue key and its priority
Issue issue  = issue
def Priority =  issue.getPriorityObject().getName()
def tz = TimeZone.getTimeZone('GMT')
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYY");
Date created = issue.getCreated()
def strDate = sdf.format(created);

// Add values to the current date depending on the priority
if(Priority == "P1"){
    // Add 1 Day
    strDate = DateUtils.addDays(created,1).format("dd-MM-YYYY")
} else if(Priority == "P2"){
    // Add 2 Days
        strDate = DateUtils.addDays(created,2).format("dd-MM-YYYY")
}else if(Priority == "P3"){
    // Add 3 Days
        strDate = DateUtils.addDays(created,3).format("dd-MM-YYYY")
} else if(Priority == "P4"){
    // Add 4 Days
        strDate = DateUtils.addDays(created,4).format("dd-MM-YYYY")
else if(Priority == "P5"){
    // Add 5 Days
        strDate = DateUtils.addDays(created,5).format("dd-MM-YYYY")
return strDate


I hope this helps.



Thanks, works great - Had to make it:

Searcher: Free Text Searcher

Template: Text Field (multi-line)

Hi  DF,

That is the correct searcher and I am glad I could help.

If this answer is useful can you please mark it as accepted so other people with a similar question can easily find this answer in future.



Create a scripted field with the following code:

import org.joda.time.DateTime;
if("P1")) {
return new DateTime(issue.created).plusDays(1).toDate()
if("P2")) {
return new DateTime(issue.created).plusDays(2).toDate()
if("P3")) {
return new DateTime(issue.created).plusDays(3).toDate()

You should use:

Searcher: Date Time Range picker
Template: Date Time Picker

Thanks, this works as well. One minor change i had to make was changing the template to text field, because using date time picker, wouldn't give me an actual date, but it would say: 2 days, in 4 hours, etc


Making it Text field (multi-line): i got this format

example: Mon Feb 29 18:26:35 EST 2016



We have upgraded to JIRA 7 and this custom field is throwing an error now. Do you know why?

See attachmentScreen Shot 2016-06-15 at 2.10.49 PM.png

I think the variable "Issue" should be "issue" with lower letter 'i'



Thanks for quick reply - we noticed that mistake and made corrections but now are asking to make more changes. Screen Shot 2016-06-15 at 3.20.54 PM.png

This was resolved by: 

Switching ("1-urgent")


issue.getPriority ().name == ("1-Urgent")

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,718 views 17 21
Read article

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