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

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

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

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

Hi @Tuncay Senturk -Snapbytes-  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

Hi again,

You should remove 

def issue = event.issue as Issue

HI :)

Tried it..same errors. 

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.

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 -Snapbytes-  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

Hi,

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

def event = event as IssueLinkCreatedEvent

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

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

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.

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

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 ...

260 views 1 2
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