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"
}

 

 

Thanks,
Ash.

1 answer

This widget could not be displayed.

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.

 

Thanks.

Ash.

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.

ad.jpg

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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

485 views 3 18
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