How to get the current issue key in context of a scriptrunner listener

Peter Brodt March 3, 2020

Hi Folks,

I try to implement a create issue and update listener. My code works fine as long as I use a hard coded issue key. I have tried all day long to find out how to retrieve the current issue key in listener context.

This is my code

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.issue.IssueEventBundle;
import com.atlassian.jira.event.type.EventType;
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.sql.Sql
import java.sql.Driver

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)


def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_13800");// here replace the ID with ID of your custom field.
def issueManager = ComponentAccessor.getIssueManager()

// here is my problem
def issue = issueManager.getIssueObject("ANFO-331")

//
def value = issue.getCustomFieldValue(customField);

log.warn value

Any suggestions how to solve the problem? Thanks in advance.

Peter

1 answer

1 accepted

2 votes
Answer accepted
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 3, 2020

Issue issue = event.getIssue()

Peter Brodt March 4, 2020

Perfect Payne. You really made my day. 

Thanks a lot

Like Payne likes this
Tamil June 25, 2020

Hi Payne,

 

I want to retrieve the issue key and update the issue key value in custom field. i am adding script in Behaviour. But i am getting error. Could you please help on this?

Like # people like this

Suggest an answer

Log in or Sign up to answer