Example scripts
To homepage
Jira

Calculate Custom Field on Work Item Update
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira
Language |
groovy
def eventWorkItem = Issues.getByKey(issue.key as String)
final spaceKey = 'TEST'
if (eventWorkItem.projectObject.key != spaceKey) {
logger.info("Wrong Space ${eventWorkItem.projectObject.key}")
return
}
//get the value of each of the custom fields or use 0 as default if a value isn't set yet
def input1 = eventWorkItem.getCustomFieldValue("Custom Field 1") as Integer ?: 0
def input2 = eventWorkItem.getCustomFieldValue("Custom Field 2") as Integer ?: 0
def output = input1 + input2
//do not attempt to update the result if it is the same as the existing one.
if(eventWorkItem.getCustomFieldValue("Output Custom Field") == output) {
logger.info("The reulst was the same as the existing one, no update needed.")
} else {
eventWorkItem.update {
setCustomFieldValue("Output Custom Field", output)
}
logger.info("Output Custom Field updated to ${output}")
}Having an issue with this script?
Report it here