Calculated custom field using script runner

Hi All,


I have created a scripted field for issue age and created another scripted field to to describe the issue age but fails to populate the second custom field, can any oe help me to modify this code.


def Age = getCustomFieldValue("Issue Age in Days").getValue()

if (Age <= 180){
return "Less Than 6 months"

if (Age >= 180){
return "6-12 Months"
if (Age > 365){
return "More than 12 Months"




1 answer

0 votes

Is the field a numeric field?

Both are scriptrunner  scripted fields Nic, is it possible to display string type values in scripted field ?

That's not quite what I asked, but re-reading the question and that comment suggests an answer.

It sounds like you are trying to have one scripted field calculate something, and then a second do another calculation based on the first one.

Do not do that if the fields are on the same issue.  It fails in interesting ways.  You'll need to decouple it, so that both fields do the calculation independently.

Thanks for the reply Nic.

Here is what I'm doing, I have a scripted field which calculates issue age and displays in number format (1,2,3...) and I'm planning to have another scripted field on the same issue, if the number on the first scripted field is below 180 then second scripted field need to print  "Less than 6 months" and if the number the number greater than 180 and less than 365 then second scripted field need to print "6-12 months" if the number on the first scripted field is greater than 365 then the second one need to print  "more than 12 month" 

this is the requirement so we can do reporting on this.




Thank you, Nic.


Able to fix the code but don't know how these issues work in reporting.

I'm not sure what you're looking for help with now.  I'll try to explain my answer differently and hope it helps a bit:

For the field "Age"

  • Set it to have numeric output
  • Write code that calculates a number of days
  • Return the number of days

For the field "Age description"

  • Set it to have text output
  • Copy the code you used in "Age", except the "return"
  • To the end of that code, add your three if statements that return a descriptive string

You are doing the calculation twice, but it removes the dependency of one field on the other (which is what is going wrong here)


Thank you for the reply Nic,  How accurate are these two values for reporting?. (We are using arsenal dataplane plugin for reporting)

I found this in my research, is there any update in scriptrunner plugin since this comment is in 2011.


There's *lots* of updates, but Jamie's comment absolutely stands here.

Your fields will be totally accurate in JIRA.  Dataplane supports scripted fields if I understand it correctly, so you don't need to worry there either.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

447 views 8 26
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