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
4,367,701
Community Members
 
Community Events
168
Community Groups

event.getIssue() returns issue number

Hello,

I just got a job as jira admin and there are many listeners made by the ones before me.

Now listeners that were selecting issues to work with them started failing because event.getIssue()/event.issue returns now the issue number, not the issue object and therefore all functions like issue.getCustomFieldValue(field name) are returning null. 

This started happened around 15.08.2022. 

2 answers

Hello!

Olly here from Adaptavist Support - just looking at our Release Notes, I don't see anything has changed with the way we handle what you've mentioned!

What Jira version and ScriptRunner version are you using out of curiosity?
I think that might affect what you're experiencing.

For all the latest versions though, when I create a Listener with the 'Issue Updated' event, I can retrieve an Issue Object by doing:

def issue = event.issue

I can also see the Object type within the Script Editor:

Screenshot 2022-09-02 at 11.04.33.png

This log message will return the Key (e.g. EG-1), however the object is still an Issue as per the image and Jira API linked above.

log.warn(issue) 

When using the issue.getCustomFieldValue() you need to use a CustomField Object, as per the API.

You could do this by doing something like:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

//define the issue
def issue = event.issue

//custom field manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//define the Custom Field
def customField = customFieldManager.getCustomFieldObjectsByName("Example Custom Field").first()
def customFieldValue = issue.getCustomFieldValue(customField)

log.warn(customFieldValue)

Which will return the value of that Custom Field!

Hope this answers your query!

Thanks,

Olly

This is ok. Thank you very much!

Hi @florin.ionut.pana

Could you please share your full Listener code so I can take a look at it and provide some suggestions?

Also, could you please confirm if you are using ScriptRunner for Jira Server or Cloud?

Thank you and Kind regards,

Ram

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.event.type.EventDispatchOption


log.warn("Event " + event)
def issuename = event.getIssue() // get issue
log.warn("Issue name " + issuename)

def issue = event.getIssue()
def issue2 = event.issue;
log.warn("Issue2 " + issue2)

def assignmentGroup_cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("L3 FTE/ Effort") // select field
def assignmentGroup_cfValue = assignmentGroup_cf.getValue(issue) // select field value

log.warn("Assignment " + assignmentGroup_cfValue)

 

and the log is:

2022-09-02 09:48:10,369 WARN [runner.ScriptBindingsManager]: Event com.atlassian.jira.event.issue.IssueEvent@1a6d784e[issue=ESM-94600,comment=<null>,worklog=<null>,changelog=[GenericEntity:ChangeGroup][issue,108137][author,JIRAUSER11900][created,2022-09-02 09:48:09.391][id,197394],eventTypeId=2,sendMail=true,params={eventsource=action, baseurl=(deleted_urll)] 2022-09-02 09:48:10,369 WARN [runner.ScriptBindingsManager]: Issue name ESM-94600 2022-09-02 09:48:10,369 WARN [runner.ScriptBindingsManager]: Issue2 ESM-94600 2022-09-02 09:48:10,376 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2022-09-02 09:48:10,376 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null java.lang.NullPointerException: Cannot invoke method getValue() on null object at Script507363.run(Script507363.groovy:24)

 

note: line 24 is def assignmentGroup_cfValue = assignmentGroup_cf.getValue(issue) //

Hi @florin.ionut.pana

In your code, it looks like you have declared the event.issue twice, i.e.

def issuename = event.getIssue() // get issue

and

def issue = event.getIssue()

 

In the former, you have named the variable issuename, but you are actually invoking the entire issue object.

If you want to get the issue's name specifically, you will need to do:-

def issue = event.issue
def issuename = issue.name

 

Also, may I know what type of events you are using for your Listener? Is it the Issue Created event or the Issue Updated event?

If you are using any other event types, invocating the issue object will not work in that approach.

 

Thank you and Kind regards,

Ram

That was just for test. But now I got an error with

def isssuename = issue.name

Error: [Static type checking] - No such property: name for class: com.atlassian.jira.issue.Isssue

Hi @florin.ionut.pana

Could you please share the actual code you are using and a full screenshot of your Listener configuration?

Thank you and Kind regards

Ram

It seems that is not a problem, when I run the script, it's working.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events