hy All,
we would simply like to multiply two values set in two different field. The result should be shown in the third field.
Any idea how this can be done?
Cheers
Guido
@Guido Eckenwalder Welcome to the community and I hope my suggestion answer your questions.
There are two ways to do this but it will be also dependent if your using Cloud or Data Center editions.
First would be with Automation for Jira using a smart value calculation or math expression. It will be dependent on if this is happening in 1 project or many to know if you should use global automation or project automation > Here is a link to the smart value math expression https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/
For Automation for Jira you would use a If field value change trigger and add condition to and edit field value with the output to the field value with the smartvalue math expression imbedded to that field you would want he outcome to be in.
Second way would be to use scriptrunner add-on to do this for you. There is a script in the the scriptrunner cloud console in browse> Calculated Customer Field
here is the groovy script
// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def input1CfId = customFields.find { it.name == 'Custom Field 1' }?.id
def input2CfId = customFields.find { it.name == 'Custom Field 2' }?.id
def outputCfId = customFields.find { it.name == 'Output Custom Field' }?.id
def projectKey = "TP"
if (issue == null || ((Map)issue.fields.project).key != projectKey) {
logger.info("Wrong Project ${issue.fields.project.key}")
return
}
def input1 = issue.fields[input1CfId] as Integer
def input2 = issue.fields[input2CfId] as Integer
if (input1 == null || input2 == null) {
logger.info("Calculation using ${input1} and ${input2} was not possible")
return
}
def output = input1 + input2
if (output == (issue.fields[outputCfId] as Integer)) {
logger.info("already been updated")
return
}
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()
I hope this helps you with your issue. Please let me know if this answers your question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.