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)
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Was able to get past the error. Thanks for the 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.