Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Check the Value of a Custom Field when it Changes

Features
Listeners
Tags
Created 1 year ago, Updated 8 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.11 - 9.1)
compatibility bullet
ScriptRunner For Jira (7.8.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor

//Define the current Issue and the desired Custom Field Name
def issue = event.issue
def customFieldName = '<CUSTOM_FIELD_NAME>'

//Define Change History Manager and retrieve the last updated item for this issue
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def lastChangedItem = changeHistoryManager.getAllChangeItems(issue).last() as String

//Then check if the latest update to the Issue had a change to this Custom Field
if (lastChangedItem.contains(customFieldName)) {
    //Add code to be executed if this condition is met

    //For example, if the Custom Field is a certain value
    def customFieldManager = ComponentAccessor.customFieldManager
    def customFieldObject = customFieldManager.getCustomFieldObjectsByName(customFieldName).first()
    def customFieldValue = issue.getCustomFieldValue(customFieldObject) as String

    if (customFieldValue == '<DESIRED_VALUE>') {
        //Execute further code, for example, send a log message
        log.warn("The Custom Field $customFieldName has a value of $customFieldValue")
    }
}
Having an issue with this script?
Report it here