Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

IssueLinkCreatedEvent not working as expected

Rajakumar Sivakumar January 7, 2019

Hi Team,

I'm trying to update the security level while linking from "More".

I wanted the security level of the destination issue to be set as the source issue after linking.

I get run time error, after linking. 

Please find below my code and the error and kindly do the needful,

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.atlassian.jira.event.issue.IssueEvent

def IssueEvent event = event

def issue = event.issue as MutableIssue

 

def issueManager = ComponentAccessor.issueManager
def issueType = "Acquired Product Defect"
def linkedIssueType = "SRT Event"


def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager)
def issueSecurityLevelManager = ComponentAccessor.issueSecurityLevelManager
//def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def SourceSecurityLevel = ComponentAccessor.getIssueSecurityLevelManager().getSecurityLevel(issue.getId())


def eventTypeManager = ComponentAccessor.getEventTypeManager();
def eventType = eventTypeManager.getEventType( event.getEventTypeId() );
def eventTypeName = eventType.getName();

if (issue.getIssueType().name == issueType) {
if( eventTypeName == "Issue Link Created" ){
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
Issue linkedIssue = issueLink.getDestinationObject() as MutableIssue
if (linkedIssue.getIssueType().name == linkedIssueType) {
linkedIssue.setSecurityLevelId(SourceSecurityLevel.getId())

}
}
}
}

 

 

 

Error:

 

2019-01-07 07:51:18,973 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-01-07 07:51:18,974 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent, file: <inline script>
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent@10f49809' with class 'com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent' to class 'com.atlassian.jira.event.issue.IssueEvent'
	at Script873.run(Script873.groovy:12)



Regards
Rajakumar Sivakumar
rajakumar.s@hcl.com

 

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 13, 2019

Hi @Rajakumar Sivakumar this is untested but should work

 

/*
* Update the security level while linking from action
* This should get the issueSecurityLevel from the issue and set it in the linked Issue
* When the issueType is "Acquired Product Defect" and the linked issueType is "SRT Event"
*/

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser

MutableIssue issue = event.issue as MutableIssue
String issueType = "Acquired Product Defect"

if (issue.getIssueType().name.equals(issueType)) {

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String linkedIssueType = "SRT Event"
MutableIssue linkedIssue

issueLinkManager.getOutwardLinks(issue.id).each {
IssueLink issueLink ->
linkedIssue = issueLink.getDestinationObject() as MutableIssue

if (linkedIssue.getIssueType().name.equals(linkedIssueType)) {

linkedIssue.setSecurityLevelId(issue.getSecurityLevelId())
issueManager.updateIssue(currentUser, linkedIssue,EventDispatchOption.DO_NOT_DISPATCH,false)
ComponentAccessor.getComponent(IssueIndexingService).reIndex(linkedIssue)

}
}
}
Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 13, 2019

Forgot to mention that this only work as spected when you specify the event type in the select list as "IssueLinkCreated" and if the IssueSecurityScheme is used in both issueTypes (same project or same IssueSecurityScheme in different projects).

0 votes
Jenna Davis
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.
January 8, 2019

Hi Rajakumar, 

While I'm not sure that it covers every aspect you're wanting, this community question contains a response that shows how to set a security level using a listener. I think this is what you're wanting to do and that this post will help point you in the right direction. 

Please let me know if this helps you out or if I can help you sort anything else out. If you continue having trouble can you please send me a screenshot of the listener you currently have setup so that I can get replicate what you're doing. 

Hope this helps! :)

Jenna Davis

TAGS
AUG Leaders

Atlassian Community Events