Forums

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

Behaviour script to add comment whenver the priorities change

Sharadkumar Bangera
Contributor
November 18, 2020

I  am looking for Script to add in behavior field with detailed step which fulfils my requirements

My requirement is whenever we change the priority in jira it displays normally Priority changed from Major to Minor but it does not display the same message in service portal which customer refer. Customer is always blind in service portal when the priority is changed

Hence i am looking or a script whenever we change the priority from Major to minor in Jira the comment to be automatically added in Service portal which is visible to customer "The priority for this issue has changed from Major to Minor"

I am aware it works with "Automation for Jira - Server" but i dont have this application and looking for only script runner

Thanks and Regards,

Sharad

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
}
}

getFieldById(getFieldChanged())

gets the ID of the field the script is attached to. So the behaviour would be linked to the Priority field in your case.

Suggest an answer

Log in or Sign up to answer