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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get current issue when I use IssueLinkCreatedEvent event

Hi,

I created a script that sets specified value in Y custom field when I set specified value in X field.
X field is "Epic Link" (type: Epic Link Relationship) and Y it "Organizational Unit" field (type: Select List (single choice).
When I set constant issue key, script works correctly, but when I place script in Script Listener and set Events to "IssueLinkCreatedEvent" my script don't see a current issue.
In console I get information about null object.

How I can get current editing issue in this case?

Actually I try get current issue by code:
Issue issue = issue.

I tried also this method:
Issue issue = (Issue)jiraHelper.getContextParams().get("issue");

but that did not help.

 

2 answers

1 accepted

2 votes
Answer accepted

Hello @Paweł Jakimiak

In listeners you can get issue from event, like this

Issue issue = event.issue

Unfortunately, I receive this error:

2018-09-04 13:50:57,414 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2018-09-04 13:50:57,430 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent, file: <inline script>
groovy.lang.MissingPropertyException: No such property: issue for class: com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
 at Script316.run(Script316.groovy:9)

Oh, this is IssueLink event.

Is contains IssueLink object, which have methods to retrieve source and destination issues

Issue destinationIssue = event.getIssueLink().getDestinationObject()
Issue sourceIssue = event.getIssueLink().getSourceObject()

Thank you very much for your help. It's works.

Issue destinationIssue = event.getIssueLink().getDestinationObject()
Issue sourceIssue = event.getIssueLink().getSourceObject()

I use this code, but it doesn't work for me. 

Untitled.png

Can anybody help?

I'm getting this error too.  Has anyone solved this?

@Eric Lakey @Aditya Wijanarko 

I managed to resolve it:

Issue issue = null; //Indicates a new Issue Object, without this event. doesn't seems to work

if(event.getClass().toString() == "class com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent"){ // Need some way to check if link is created or deleted, i saw something like this: (event instanceOf issueLinkCreatedEvent) but this didn't work for me
def event = event as IssueLinkCreatedEvent
issue = event.getIssueLink().getSourceObject()
} else if(event.getClass().toString() == "class com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent"){
def event = event as IssueLinkDeletedEvent
issue = event.getIssueLink().getSourceObject()
} else issue = issue; //In my code, I am using also "Issue updated" event, if you want only check if Link is created or deleted, just erase this
Like Asaf_Porat likes this

Hi @Damian Wodziński 

Did that code work for you? Your comments are saying something differently and I get a:

unable to resolve class IssueLinkCreatedEvent

Can you also post your import section?

Best
Daniel

Now I know. What is often missing for beginners - which class to import. In this case do

import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent

hi i have this problem to, i want to delete issue link when user want to create link to another project,and user only can link issue to current project that issue is in,i try this code 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.event.issue.EventUtils

//import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
Issue issuedes = event.issue;
Issue issuesou;

ProjectManager projectMgr = ComponentAccessor.getProjectManager();
//Issue destinationIssue = IssueLink.getDestinationObject()
//Issue sourceIssue = IssueLink.getSourceObject()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
Issue currentIssue = issuesou
//def currentProject = currentIssue.projectObject.name
def linkedIssue = issuedes
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssue.id).each { issueLink ->

linkedIssue = issueLink.getDestinationObject()

if( linkedIssue.getProjectObject().getKey() != currentIssue.getProjectObject().getKey() )
{

issueLinkManager.removeIssueLink(issueLink, user)
}

}

 

and i have this error 

 

2019-01-08 11:21:03,878 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-01-08 11:21:03,878 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException: Cannot get property 'id' on null object
 at Script3086.run(Script3086.groovy:23)

i think i can not refer to sourceIssue and  event.issue; code is for destinationIssue,

please help me thank

Issue issuesou; 

This indicated null object

Then:

Issue currentIssue = issuesou

 

So when you try to do this:

issueLinkManager.getOutwardLinks(currentIssue.id).each

It causes the problem, it cannot do anything on null object.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you