Calculated custom field using script runner

Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 12, 2017

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

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2017

Is the field a numeric field?

Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 12, 2017

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2017

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.

Like Mateusz Muller likes this
Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2017

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.

Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2017

Thank you, Nic.

 

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 13, 2017

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)

 

Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2017

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 13, 2017

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
TAGS
AUG Leaders

Atlassian Community Events