Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Behaviour script

Sharadkumar Bangera
Contributor
November 19, 2020

Hi,

Can someone please help me with script.

I m looking for  beviour script, if i change field value of  Priority to Blocker the Comment to be added in Jira .

The comment should be Prioity is changed fro OLD value to NEW value

 

1 answer

0 votes
Tom Lister
Community Champion
December 14, 2020

Hi @Sharadkumar Bangera 

You can identify when a field changes using getFieldChanged() method

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

def customFieldManager = ComponentAccessor.getCustomFieldManager()
@BaseScript FieldBehaviours fieldBehaviours

// import org.apache.log4j.Level
// import org.apache.log4j.Logger
// def log = Logger.getLogger("com.acme.CreateSubtask")
// log.setLevel(Level.DEBUG)
def fieldChanged = getFieldById(getFieldChanged())
if(fieldChanged.getFieldId().compareTo( "customfield_12300") == 0)
{
def sites = getFieldById("customfield_10200")
// log.debug("****~" + fieldChanged)

// log.debug ("Field changed : $fieldChanged and it's value is ${fieldChanged.value} - ${fieldChanged.rawValue}")
if (fieldChanged.getValue() == "Y") {
sites.setFormValue("")
fieldChanged.setFormValue("")
} else {
// no action
}
}

log.debug ("Field changed : $fieldChanged and it's value is ${fieldChanged.value} - ${fieldChanged.rawValue}")

should show current and previous values.

That can be used to create a comment.

Suggest an answer

Log in or Sign up to answer