import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dc = getFieldById("customfield_17120")
def dv = getFieldById("customfield_17109")
def cl = getFieldById("customfield_17110")
def dcval = dc.getValue()
def dvval = dv.getValue()
def clval = cl.getValue()
def Sum = dvval + dcval; //calculate
if (dvval != "" && clval != "" ) {dc.setFormValue(Sum)}
Hi @Thomas Vollbrecht ,
This is possible. You might need to adapt to the custom field types though. For example, if they are number fields, you would need to do a few checks :
def dc = getFieldById("customfield_17120")
def dv = getFieldById("customfield_17109")
def cl = getFieldById("customfield_17110")
def dcval = dc.getValue()
def dvval = dv.getValue()
if (dvval.isNumber() && dcval.isNumber()){
def Sum = Double.parseDouble(dvval) + Double.parseDouble(dcval)
cl.setFormValue(Sum)
}
If they are text fields, it is straight forward.
Antoine
The fields are number fields, but what for checks i need to do?
I test your written code, but it doesn´t work.
Could you please send me a instruction or something like that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please detail what you need more precisely ? Then I will be able to provide the steps.
Behaviours will detect any change to the mapped field and execute the script each time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fields:
Field01 (in €) Number field
Field02 (in €) Number field
Field03 (in%) Number field
Calculate: FieldID01 / FeldID02 * 100
Thanks for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So this would be the whole script. Update the custom field ids.
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int numberField1Id = 13301
def numberField1 = getFieldById("customfield_" + numberField1Id)
def numberField1Value = numberField1.getValue()
int numberField2Id = 13302
def numberField2 = getFieldById("customfield_" + numberField2Id)
def numberField2Value = numberField2.getValue()
int numberField3Id = 13303
def numberField3 = getFieldById("customfield_" + numberField3Id)
if (numberField1Value.isNumber() && numberField2Value.isNumber()) {
def result = (Double.parseDouble(numberField1Value) / Double.parseDouble(numberField2Value)) * 100
numberField3.setFormValue(result.trunc(2))
}
numberField3.setReadOnly(true)
Remove the setReadOnly if you want your users to be able to edit the field.
You need to map this script to the Field01 and Field02 behaviours.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.