IssueLinkCreatedEvent generates errors and fails with scriptrunner listener

Kevin Dalton September 26, 2018

2018-09-26 11:27:07,218 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2018-09-26 11:27:07,218 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent, file: groovy.lang.MissingPropertyException: No such property: issue for class: com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent at Script128.run(Script128.groovy:20)

 

import org.apache.log4j.Category
import java.util.*
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.atlassian.jira.bc.issue.IssueService
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.IssueManager
import webwork.action.ActionContext
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder


Issue issue = event.issue


def issueManager = ComponentAccessor.getIssueManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeHolder = new DefaultIssueChangeHolder()


def linkMgr = ComponentAccessor.getIssueLinkManager()
def projectMgr = ComponentAccessor.getProjectManager()
def fieldManager = ComponentAccessor.getFieldManager()
def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField

def request = ActionContext.getRequest()
def children = 0
def params = request.getParameterMap()
def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue

def EK = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14803") // External Key
def EKVal = issue?.getCustomFieldValue(EK)

def PL = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_17617") // Parent Link
def PLVal = issue?.getCustomFieldValue(EK)

 

if (request && EKVal != null && PLVal == null && (issue.issueTypeObject.name == 'Epic' || issue.issueTypeObject.name == 'Story')) {

for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
def issueLinkTypeName = link.issueLinkType.name
def linkedIssue = link.getDestinationObject()
def linkProjectName = linkedIssue.getProjectObject().getName()
def linkedIssueKey = linkedIssue.getKey()
def linkedIssueID = linkedIssue.getId()
log.debug ("Inside 4 loop..." + issueLinkTypeName + "--" + linkProjectName)

//look for a link that is child of in PC
if (! (issueLinkTypeName == "Parent" && linkProjectName == "Project Central")) {
log.debug ("Not Parent...")

} else if ((issueLinkTypeName == "Parent" && linkProjectName == "Project Central") ||
(issueLinkingValue.linkedIssues?.toString()?.contains("PC-") && issueLinkingValue.linkDescription?.toString()?.contains("is a child of"))) {
log.debug ("Parent...")
children = children + 1
}
PL.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(PL), linkedIssueKey),changeHolder)
log.debug ("4 Restarting..." + children)
}
}

 

2 answers

1 accepted

0 votes
Answer accepted
Daniel Wong
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.
September 27, 2018

Hi Kevin,

I'm not sure what your code actually does but at a glance, I think you're trying to setup some sort of issue linking in a listener.

The error you're looking for is in line 20 - 

Issue issue = event.issue

You need to declare the event type. Try the below:

def IssueEvent event = event
def issue = event.getIssue()

I recommend going through Scriptrunner's documentation for more information on how to build Listeners - https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_custom_listeners

0 votes
Kevin Dalton September 27, 2018

Trying to make a listener that catches the link created event and if it is a certain link type it populated the parent link field automatically

Kevin Dalton September 27, 2018

Was able to get past the error.  Thanks for the help

BarL October 6, 2019

@Kevin Dalton  Can you please share with us how did you managed to get past the error?  

DVK April 11, 2020

@Kevin Dalton Could you please share the code with us get the event as Issue

Kevin Dalton April 13, 2020

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.atlassian.jira.issue.link.IssueLinkManager
import webwork.action.ActionContext;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Category
import com.atlassian.jira.issue.link.IssueLinkManager
log.setLevel(org.apache.log4j.Level.DEBUG)

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def projectMgr = ComponentAccessor.getProjectManager()
def fieldManager = ComponentAccessor.getFieldManager()
def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField


def Issue issue = issue


def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def request = ActionContext.getRequest()
def children = 0


def EK = customFieldManager.getCustomFieldObject("customfield_14803") // External Key
def EKVal = issue?.getCustomFieldValue(EK)
def PL = customFieldManager.getCustomFieldObject("customfield_17617") // Parent Link
def PLVal = issue?.getCustomFieldValue(PL) as String
def EL = customFieldManager.getCustomFieldObject("customfield_17617") // Epic Link
def ELVal = issue?.getCustomFieldValue(EL)

log.debug ("Source External Key Name..." + EK + '---' + EKVal)
log.debug ("Source Parent Key Name..." + PL + '---' + PLVal)


if (request && EKVal != null && PLVal != null && (issue?.issueTypeObject.name == 'Epic' || issue?.issueTypeObject.name == 'Story')) {
def params = request.getParameterMap()
def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue

for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
def issueLinkTypeName = link.issueLinkType.name
def linkedIssue = link.getDestinationObject()
def linkProjectName = linkedIssue.getProjectObject().getName()
def linkedIssueKey = linkedIssue.getKey()
def linkedIssueID = linkedIssue.getId()
def linkedIssueSum = linkedIssue.getSummary()
log.debug ("Inside 4 loop..." + "--" + issueLinkTypeName + "--" + linkedIssue + "--" + linkProjectName + "--" + linkedIssueKey + "--" + linkedIssueID)

//look for a link that is child of in PC
if (! (issueLinkTypeName == "Parent" && linkProjectName == "Project Central")) {
log.debug ("Not Parent...")

} else if ((issueLinkTypeName == "Parent" && linkProjectName == "Project Central") ||
(issueLinkingValue.linkedIssues?.toString()?.contains("PC-") && issueLinkingValue.linkDescription?.toString()?.contains("is a child of"))) {
//log.debug ("Parent...")
children = children + 1
}

//log.debug ("4 Restarting..." + children)
}

if (children == 0) {

def IssueID = issue.getId()
def ParentKey = ComponentAccessor.getIssueManager().getIssueObject(PLVal)
def ParentID = ParentKey.getId()

log.debug ("Issue ID..." + IssueID)
log.debug ("Parent ID..." + ParentID)

linkMgr.createIssueLink(IssueID, ParentID, 10800, 1, currentUser)
}
//log.debug ("Done...")

}

Suggest an answer

Log in or Sign up to answer