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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • 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

Get value of custom script field is always 0

Hi at all,

in our company we use JIRA Server 8.5.1. I have two questions and hopefully someone could help. We have the Scriptrunner in use to calculate some more detailed values, .e.g. for the functional progress.

First:

I have already used the following line to retrieve a value of a custom scripted field (number field) and it is working:

def customFieldValue = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_YYYYY").getValue(issue)

Now we needed another custom scripted field which also needs the value from another scripted field. This field is visible on the belonging issue, it has a value different from 0. I can also access this value from the script console. But when I use the exactly same code within the script for the scripted field, it always says that the field's value is 0.

We are completely lost here, as I wrote before, exactly the same code works in multiple other scripted fields. Do you have any ideas? The only thing we could image is that the other scripted fields are limited to four specific projects and the newly created scripted field is global. Could that be the reason?

Second:

When I use logging in a scripted field by invoking log.debug and then pressing the preview button, no log shows up even when I use log.setLevel(Level.DEBUG) before. In other scripted fields I bypassed this by using my own logger: logger=Logger.getLogger("com.company.controlling.newValue") Now I tried it this way as usual and it is not working. The funny thing is that when I use a name for the logger which is already in use for another scripted field, e.g. logger=Logger.getLogger("com.company.controlling.oldValue") the logging works by pressing the preview button.

It would be really helpful if someone could provide help, especially for the first question.

Thanks,

Manuel

1 answer

0 votes

Is the second scripted field on the same issue as the first one?

This will often break because you can't be sure which field will be recalculated first when the issue is reindexed (or, in fact, how many times!).  The way to "fix" that is to not base a scripted field on another one if they're going to be indexed in the same batch (i.e. same issue).  Most of the time, you have to duplicate the code. 

If, for example, you have

field a = x + y

field b = a + z

Replace the second one with a duplicate calculation, such that field b = x + y + z

Thanks for your answer! The scripted fields are for different issues.

The first issue is of type A and has a scripted field AFunctionalProgress. The second scripted field (the new one) is for issue type B and therefore its name is BFunctional Progress. Multiple issues of type A could be linked to type B. I iterate through all these issues of type A and try to get AFunctionalProgress with the mentioned code.

It is strange that the thing you describe always works in our cases. For issue type A, we have the scripted fields AValue1 and AValue2 where AValue2 needs is based on AValue1.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

146 views 1 8
Read article

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