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

IssueLinkCreatedEvent generates errors and fails with scriptrunner listener

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

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

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

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

314 views 1 3
Join discussion

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