Scriptrunner- No such property: issue for class: com.atlassian.jira.event.issue.link.IssueLinkCreate

BarL October 26, 2019

Hi,

I created a listener that runs on "IssueLinkCreatedEvent".

The listener works well but I keep getting this error on "def issue = event.issue as Issue" line:

2019-10-26 12:03:14,177 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 Script2068.run(Script2068.groovy:16)
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:178)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$3.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$3.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:167)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$2.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener.doScript(CustomListener.groovy:123)

Part of my script:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent
import org.apache.log4j.Level
import org.apache.log4j.Logger

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = event.issue as Issue

  Does anyone know why?

2 answers

0 votes
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 27, 2019

Hi, since IssueLinkCreatedEvent has not the method getIssue() you cannot use the line

def issue = event.issue as Issue

during your script, please try the following instead as a base for your script:

 

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.nolddor")
log.setLevel(Level.DEBUG)

def sourceIssue = event.issueLink.sourceObject
def destinationIssue = event. issueLink.destinationObject

log.debug "An IssueLinkCreate event has been catched"
log.debug "Issue (from): ${sourceIssue.key}"
log.debug "Issue (to): ${destinationIssue.key}"

 

 

After creating a link the following traces should appear in the log file:

[...] /secure/LinkJiraIssue.jspa [com.nolddor] An IssueLinkCreate event has been catched
[...] /secure/LinkJiraIssue.jspa [com.nolddor] Issue (from): EMEA-920
[...] /secure/LinkJiraIssue.jspa [com.nolddor] Issue (to): LATAM-517

 

 

Hope this helps,

Regards

BarL October 27, 2019

Hi @Jack Nolddor _Sweet Bananas_  I wrote your code and did get :

2019-10-27 02:54:26,389 DEBUG [com.nolddor]: An IssueLinkCreate event has been catched
2019-10-27 02:54:26,390 DEBUG [com.nolddor]: Issue (from): PM-4847
2019-10-27 02:54:26,390 DEBUG [com.nolddor]: Issue (to): DOT-3940

 But now what?.. if I remove the  "issue = event.issue as Issue" line and replace it with your 2 liens I get a lot of errors on my whole script when it comes to the word "issue":

Error: The variable [issue] is undeclared.

Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 27, 2019

Now you have to determine wich of two issues involved during the link need to be modified and replace your issue word with either sourceIssue if you want to perform your logic against PM-4847 issue or destinationIssue if you need to perform the modificationsn against DOT-3940 issue.

 

Regards

BarL November 18, 2019

@Jack Nolddor _Sweet Bananas_  Thanks! it works :) , maybe you can help me with one last thing - 

In my code I update links that are connected to the same issue. 

if (destinationIssue.getIssueType().getName() == "Defect" && responsibleTeamCfValue == "Sustaining") {
for (i in BundledEpics) {
if (i.getSummary().contains("Documentation")) {
DocTargetCF.updateValue(null, DocLinkedIssue, new ModifiedValue(DocLinkedIssue.getCustomFieldValue(DocTargetCF), i), new DefaultIssueChangeHolder())
}
}
for (i in BundledEpics) {
if (i.getSummary().contains("Escalations")) {
EscalationTargetCF.updateValue(null, EscalationIssue, new ModifiedValue(EscalationIssue.getCustomFieldValue(EscalationTargetCF), i), new DefaultIssueChangeHolder())
}
}
}

The issue is that if I have two "Documentation" links, it only updates the first one.

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2019

Hi @BarL 

IssueLinkCreatedEvent does not have Issue access directly as seen in the API here.

Because there are two issues that are linked.

You can get event.issueLink and then get Source and Destination issues as below

def issueLink = event.issueLink

def sourceIssue = issueLink.sourceObject

def destinationIssue = issueLink.destinationObject

I hope I was helpful

BarL October 27, 2019

Hi @Tuncay Senturk  Thanks for responding.

When I add thous lines I get errors:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent
import org.apache.log4j.Level
import org.apache.log4j.Logger

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = event.issue as Issue
def issueLink = event.issueLink
def sourceIssue = issueLink.sourceObject
def destinationIssue = issueLink.destinationObject

 For def issueLink = event.issueLink line I get Error: No Souch property: issueLink for class: com.atlassian.jira.event.issue.IssueEvent

For def sourceIssue = issueLink.sourceObject line I get Error: No souch property: sourceObject for class: java.lang.object

For def destinationIssue = issueLink.destinationObject line I get Error: No souch property: destinationObject for class: java.lang.object

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 27, 2019

Hi again,

You should remove 

def issue = event.issue as Issue
BarL October 27, 2019

HI :)

Tried it..same errors. 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 27, 2019

Hi again,

Is it possible that you use same code for different event types?

For your first run you got below error:

No such property: issue for class: com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

As I mentioned for IssueLinkCreatedEvent you can get source and destination issues with the code I provided.

In the second run you got below error:

No Souch property: issueLink for class: com.atlassian.jira.event.issue.IssueEvent

 issueLink property is not valid for IssueEvent, it is a property for IssueLinkCreatedEvent

if you use my code in IssueLinkCreatedEvent, you should not get "No Souch property: issueLink for class: com.atlassian.jira.event.issue.IssueEvent" error

I hope I was clear, if it was not clear, please let me know with the full code, then I will help.

BarL October 28, 2019

Hi thanks for helping me, I still get the same errors . I use only one event :"IssueLinkCreatedEvent". here is my full script with @Tuncay Senturk  code lines.

@Jack Nolddor _Sweet Bananas_  Tried your solution as well with no luck, when I removed the "def issue" line and replaced "issue" with "destinationIssue":

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Level
import org.apache.log4j.Logger

def log = Logger.getLogger("com.nolddor")
log.setLevel(Level.DEBUG)

def issueLink = event.issueLink
def sourceIssue = issueLink.sourceObject
def destinationIssue = issueLink.destinationObject
//def sourceIssue = event.issueLink.sourceObject
//def destinationIssue = event.issueLink.destinationObject
def issue = event.issue as Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def issue = event.destinationIssue as Issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def epicLinkCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10002')
def epicLinkCfValue = issue.getCustomFieldValue(epicLinkCf).toString()
def responsibleTeamCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_14108')
def responsibleTeamCfValue = issue.getCustomFieldValue(responsibleTeamCf).toString()
def targetIssue = issueManager.getIssueObject(epicLinkCfValue)
// Find Bundle key of linked Defect Epic
def EpicBundleCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_17004')
def EpicsBundleValue = targetIssue.getCustomFieldValue(EpicBundleCf).toString()
def DocumentationlinkName = 'Documentation Task'
def EscalationlinkName = 'Sustaining Link'
// Find the Defect's Documentation link issue
def DocLinkedIssue = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getInwardIssues(DocumentationlinkName)[0]
// Find the Defect's Escalation link issue
def EscalationIssue = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getInwardIssues(EscalationlinkName)[0]
def targetIssue3 = issueManager.getIssueObject(EpicsBundleValue)
// Get the Bundle epic's list
def BundledEpics = ComponentAccessor.getIssueLinkManager().getLinkCollection(targetIssue3, currentUser).getAllIssues()
final String epicLinkFieldName = "Epic Link"
def DocTargetCF = ComponentAccessor.customFieldManager.getCustomFieldObjects(DocLinkedIssue).findByName(epicLinkFieldName)
def EscalationTargetCF = ComponentAccessor.customFieldManager.getCustomFieldObjects(EscalationIssue).findByName(epicLinkFieldName)

try {
if (issue.getIssueType().getName() == "Defect" && responsibleTeamCfValue == "Sustaining") {
for (i in BundledEpics) {
if (i.getSummary().contains("Documentation")) {
DocTargetCF.updateValue(null, DocLinkedIssue, new ModifiedValue(DocLinkedIssue.getCustomFieldValue(DocTargetCF), i), new DefaultIssueChangeHolder())
}
}
for (i in BundledEpics) {
if (i.getSummary().contains("Escalations")) {
EscalationTargetCF.updateValue(null, EscalationIssue, new ModifiedValue(EscalationIssue.getCustomFieldValue(EscalationTargetCF), i), new DefaultIssueChangeHolder())
}
}
}
} catch (Exception exc) {
log.error("Link documentation and escalation issues to epic bundle : error: ", exc)
}

  image.png

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 29, 2019

Hi,

Most probably it is compile time error, you can add below line just after the import statements.

def event = event as IssueLinkCreatedEvent
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 29, 2019

It should look like below:

 

import ...

def log = Logger.getLogger("com.nolddor")
log.setLevel(Level.DEBUG)

def event = event as IssueLinkCreatedEvent

def issueLink = event.issueLink
def sourceIssue = issueLink.sourceObject
def destinationIssue = issueLink.destinationObject
ALEXIS RODRIGUEZ September 20, 2021

Hello @Tuncay Senturk 

 

I'm new at ScriptRunner and trying to creating Listeners in ScriptRunner for Zephyr Scale Events (https://support.smartbear.com/zephyr-scale-server/docs/test-automation/integrations/creating-listeners-in-scriptrunner-for-events.html), specifically the one for when a Test Case y updated (https://library.adaptavist.com/entity/transition-an-issue-when-a-zephyr-scale-test-case-is-updated) and got this error:

issueListeners1.jpg

Because:

issueListeners2.jpg

"deprecated" because testCaseStatusModel (see line 19 of the script below) is null and i don't know why.

By the way, I configured the listener like this:

issueListeners3.jpg

Then i modified my test case to DRAFT/DEPRECATED/APROVED but still same error.

Suggest an answer

Log in or Sign up to answer