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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Issue destinationIssue = event.getIssueLink().getDestinationObject()
Issue sourceIssue = event.getIssueLink().getSourceObject()
I use this code, but it doesn't work for me.
Can anybody help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@DanielI get the following error although I have inserted the two import statements.
2022-03-14 12:50:21,858+0100 http-nio-8080-exec-6 DEBUG rlader 770x1674x1 2ytux2 172.24.15.3,172.18.7.1 /secure/DeleteLink.jspa [jira.transport.system] A link event was found
2022-03-14 12:50:21,887+0100 http-nio-8080-exec-6 ERROR rlader 770x1674x1 2ytux2 172.24.15.3,172.18.7.1 /secure/DeleteLink.jspa [c.o.scriptrunner.runner.AbstractScriptListener] *************************************************************************************
2022-03-14 12:50:21,887+0100 http-nio-8080-exec-6 ERROR rlader 770x1674x1 2ytux2 172.24.15.3,172.18.7.1 /secure/DeleteLink.jspa [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent, file: null
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent@5e41046a' with class 'com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent' to class 'com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent'
at TransportSystemListener.run(TransportSystemListener.groovy:53)
Do you have any idea what is causing this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aditya Wijanarko I have solved the problem by paying exact attention to whether I am processing an 'IssueLinkCreatedEvent' or an 'IssueLinkDeletedEvent' event. Otherwise I'm geting the above error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The accepted answer does not answer the question.
Issue destinationIssue = event.getIssueLink().getDestinationObject()
Issue sourceIssue = event.getIssueLink().getSourceObject()
I couldn't find a way to identify which of the edited current issue is the source or the destination of the IssueLink.
The Event object does not provide the information from which issue it was triggered.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From my understanding it is irrelevant from which issue the modification was done. Can you explain the reason why it is for you relevant from which issue the link modification was done?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Rethinking about it yes you are right this is irrelevant: the link can be created from both sides.
See also related post here: https://community.atlassian.com/t5/Jira-questions/IssueLinkCreatedEvent-doesn-t-have-either-parent-issue-or-issue/qaq-p/1274166#M552297
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.