Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

ScriptRunner custom event listener

Hi, this might be a bit techical.

The task is;

When one of two specific issue fields is changed:

  1. Update 2 other custom fields 
  2. Execute a HTTP request


The problem seems to be that originalissue global variable is unaccesible in the Listener. Is there a way to create a field changed listener instead of issue updated lisntener

The second thing is, some imports also do not seem accesible, though same code works perfectly in workflow post function set field value with Groovy.

Here's my code (please don't mind the issue global variable, I know that for Listeners it is event.getissue)

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;

import java.util.ArrayList;

public Object GetInsightObject(int key){
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
return objectFacade.loadObjectBean(key);

public Object GetInsightObject(String key) {
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
return objectFacade.loadObjectBean(key);

def GetInsightValue (int InsightObjectId, int InsightAttributeId) {
def insightObjectAttributeValueBeans = GetInsightObject(InsightObjectId, InsightAttributeId);
if (insightObjectAttributeValueBeans == null){
return null;
def insightValues = insightObjectAttributeValueBeans[0];
if (insightValues == null){
else {
def insightValue = insightValues.getValue();
return insightValue;

def GetInsightObject (int InsightObjectId, int InsightAttributeId){
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass);
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);

def obj = objectFacade.loadObjectBean(InsightObjectId);
if (obj == null){
return false;
attribType = objectTypeAttributeFacade.loadObjectTypeAttributeBean(InsightAttributeId);
if (attribType == null){
return false;
def attrib = objectFacade.loadObjectAttributeBean(InsightObjectId, InsightAttributeId);
if (attrib == null){
return false;
def attribValues = attrib.getObjectAttributeValueBeans();
if (attribValues == null){
return null;
else {
return attribValues;

if( (issue.get("customfield_10226") != originalIssue.get("customfield_10226")) || (issue.get("priority") != originalIssue.get("priority"))){ //service or priority field updated
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");

/* The reference to the object facade which you can use in your code */
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
def InsightObjectKey = issue.get("customfield_10226")
InsightObjectKey = InsightObjectKey[0].toString()
def tempkey = (InsightObjectKey=~/\(TSS-.*\)/)[0]
tempkey = tempkey.drop(1) // get object id
tempkey = tempkey[0..-2]
def objectID = objectFacade.loadObjectBean(tempkey).getId()

def react = 191
def react_critical = 193
def resolution = 192
def resolution_critical = 194
def priorityValue = issue.getPriorityObject.getName() //check priority value
if(priorityValue == 'P1' || priorityValue == 'P2'){ //
issue.setFieldValue("customfield_11200", GetInsightValue(objectID,react_critical)) //set new crit react time
issue.setFieldValue("customfield_11201", GetInsightValue(objectID,resolution_critical)) //set new crit resolution time
else if(priorityValue == 'P3' || priorityValue == 'P4'){ // check priority value
issue.setFieldValue("customfield_11200", GetInsightValue(objectID,react)) //set new react time
issue.setFieldValue("customfield_11201", GetInsightValue(objectID,resolution)) //set new resolution time

def SLA_id = issue.get("customfield_11100")[0].toString()[0]
//TODO http request here


1 answer

Hi @Gleb Kartashov 

You can check if the changes with a field were and get custom fields' values (original & new) from history using ChangeHistoryManager class.

def fieldHistory = ComponentAccessor.changeHistoryManager
.getChangeHistoryById( as Long).changeItemBeans
.find { it.field == 'fieldName' }

If 'fieldHistory' is not null so the field was changed and you can get values.

def oldValue = fieldHistory.getFromString()

def newValue = fieldHistory.getToString()

To set a field's value in Listener you should use IssueService class.

def issueInputParameters = ComponentAccessor.issueService.newIssueInputParameters().with {

addCustomFieldValue(Long customFieldId, String... values)


def updateValidationResult = ComponentAccessor.issueService.validateUpdate(ApplicationUser user, Long issueId, issueInputParameters)

def issueResult = ComponentAccessor.issueService.update(ApplicationUser user, createValidationResult)

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events