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 dynamically changing custom field using script runner

Need help with a Script to return the difference between current date and due date (field of issue )


if the value of the difference is 0>diiff<=7 then should return one value 

if the value of the difference is 7>diiff<=14 then should return one value 

if the value of the difference is 14>diiff<=21 then should return one value 

these values supplied should go in one custom field or 3 different field cant decide .

Please help


then these dynamically changing Scripted custom field should be reflected in the dashboard showing that an issue is due in one week ,two , three . so as to take action depending on due date .

1 answer

0 votes

This is not going to work.

Jira data is is intended to track change.  The data does not change based on time, it changes based on when people (or processes) change it.

"now" is always changing, so a script to recalculate the difference between due and now would have to run over every issue in the system once a second (a second is the smallest time Jira code bothers with, but it's not well used and humans rarely see anything more granular than a minute)

So, there aren't any scripts to do this.

You will need to have a re-think and work out some way to do this without constant recalculations.  As an example, an app that reports on a list of issues could look at the due date, compare it with "now" while it is being rendered and choose to display differently depending on the difference.  That would only run when someone runs the report, so it's not dependent on saving data for issues.

Maybe i will try to write a schedule job for it and run the script at that particular time of the day so now ()only executes during the schedule time of the job  . The main problem is the script. How do i write the Logic where the script returns the value for three different conditions to three different numeric custom field 

You've almost written that code in your question - you can translate your three "if" lines almost straight into code for java or groovy

the Problem is i am not from the Dev background and that leaves me hanging for some help with the groovy script 

When you're new to coding, it can be good to look at what others have done and learn from that.  It's also useful for expert coders too, saves them "re-inventing the wheel".

Ideally simplified stuff, code that tries to do one thing well.  For Scriptrunner, I lean on

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