Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Need to create a groovy script and script runner

Hi Team,

Please there is a requisite where user want to create a custom field which gives value to (current date – Due date ) and this value is to be used in the dash board with respect to the issues.

Basically we have an exsisting Jira project in server instance and we need a script to know the issue due date once the issue is created. This information should be displayed on the dashboard of the project.

Please help with the script.




2 answers

2 accepted

0 votes
Answer accepted
Tansu Akdeniz Community Leader Dec 17, 2020

Hi @Anuradha Yadav 

I couldn't exactly understand the problem, sorry.

There is a Due Date system field in Jira. You can add this field to any screen you like. In order to set this field, users need "Schedule Issues" permission in project's permission scheme.

Apart from that, could you please explain why do you need a script?

There is a due date field ok . Then i will add it in the screen and make it compulsory for the user to fill in the field . Then we will get due date after that how do we project it in the dashboard ?

User need this info in the dashbaord, pls help how ca i do this

0 votes
Answer accepted

You'd probably be looking for something similar to

For console debug
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

IssueManager issueManager = ComponentAccessor.getIssueManager()
Issue issue = issueManager.getIssueObject("<ISSUEKEY>")

Long currentTimeMillis = System.currentTimeMillis()
Long dueDateTimeMillis = issue.getDueDate()?.getTime()

if (currentTimeMillis && dueDateTimeMillis) {
return ((dueDateTimeMillis - currentTimeMillis) / (1000 * 60 * 60)) // millis to seconds, to minutes, to hours
} else return null


This will return a number, so your field also should return a number.

If you want to round this down, you can use the Math.round function similar to

return Math.round((Float) ((dueDateTimeMillis - currentTimeMillis) / (1000 * 60 * 60)))

I need to set up this in the board, how can I do that? please help

Hi @Radek Dostál

This code is returning NULL as value . but the problem is we cant go for each individual issue by using <ISSUEKEY> value . it should check for all the issue in the project with different status except closed .that should be the condition it should work with.


Could you please help!




I'm very confused by what you are trying to set up, where, and with what. Script fields automatically have $issue variable in the binding, so you do not need to explicitly assign the variable - that's why the whole IssueManager/Issue is commented out - that's just for testing purposes.


I was under the assumption you are adding a script field and then wanted to show that field as a column in a dashboard (filter results?). Can you clarify exactly what it is you want to set up, and what you have done so far?

Im sorry if my info was not relevant.

We are trying to work on user request for the addition of script.

User have a project in jira and User wants to display dash board with respect to all the issues, he wants create a custom field which gives value to (current date – Due date ) and this value must be on the dashboard so that user can see what is the count of the issues on due coming week. so that he can work on due issues.

this is the script I got from my colleague:


import java.sql.Timestamp
import java.time.temporal.ChronoUnit
//import com.atlassian.jira.issue.IssueManager
//import com.atlassian.jira.issue.Issue
//IssueManager issueManager = ComponentAccessor.getIssueManager()
//Issue issue = issueManager.getIssueObject("") // Get the required component
def customFieldManager = ComponentAccessor.customFieldManager
// The name of the lower date custom field
final String lowerDateCustomFieldName = "Lower Date Custom Field"
// The name of the higher date custom field
final String higherDateCustomFieldName = "Higher Date Custom Field" // Get the custom field objects
def lowerDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { == lowerDateCustomFieldName }
def higherDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { == higherDateCustomFieldName }
if (!lowerDateCustomField || !higherDateCustomField) { "Could not find one ore more of the provided custom fields"
return null
} // Get the date values from both issues
def lowerDateValue = issue.getCustomFieldValue(lowerDateCustomField) as Timestamp
def higherDateValue = issue.getCustomFieldValue(higherDateCustomField) as Timestamp
// Transform both values to instants
def lowerDateInstant = lowerDateValue?.toInstant()
def higherDateInstant = higherDateValue?.toInstant() // Change the chrono unit to obtain the difference in other time unit.
final chronoUnit = ChronoUnit.DAYS
// Calculate the difference between the lower and the higher date.
lowerDateInstant && higherDateInstant ? chronoUnit.between(lowerDateInstant, higherDateInstant) : null




anything can you relate to this for my user request?




This what user is expecting. For each app the count of due issues in weeks.



So are you adding a Script Field ( then?

 - what is the field you have created (note to limit context to avoid performance issues)

 - what is final code you placed into it

 - have you set a number searcher for the field

 - and have you set the field's template to be a Number

 - have you added the field as column in the dashboard gadget


I would advice you to check the Script Fields tutorial which contains all the information you need to set it up:

The code I provided is quite general and should work for any issue having Due date value - I did try it before I pasted here.





After long search on web . I got the below:

We need to achieve this on our project dahsboard for the client. Without using JIRA Calendar plugin. We want  to achieve this by script. Please me if you have the script.



You help will be much appriciated.





Suggest an answer

Log in or Sign up to answer

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you