field A = Custom number field,
field B =Custom number field
Want to update field C= (A-B)/B on a workflow transition.
Can someone help on this?
something like this (if field A and B are required somewhere before, you can remove the if block) :
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def customFieldA = customFieldManager.getCustomFieldObjectsByName("field A")[0]
def customFieldB = customFieldManager.getCustomFieldObjectsByName("field B")[0]
def customFieldC = customFieldManager.getCustomFieldObjectsByName("field C")[0]
def valueA = issue.getCustomFieldValue(customFieldA)
def valueB = issue.getCustomFieldValue(customFieldB)
if (!valueA || !valueB) {
return
}
def valueC = (valueA - valueB) / valueB
issue.setCustomFieldValue(customFieldC, valueC)
There are several examples of calculations in ScriptRunner at https://library.adaptavist.com/search?q=calculate
I would also think about using a scripted field to do it - this would mean the field would always be updated and valid without you needing to do a calculation on every post-function and write an additional listener to catch "field B or A have changed during an edit operation".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
wish I found out about this library sooner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We've had it for a while (maybe a year? I can't remember exactly) and when it started out, we only had a few scripts. It's been steadily growing, and I mention it more and more because it's now usually got something that's a good starting point for a lot of more complex scripts!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.