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.
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?
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.
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.