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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,760
Community Members
 
Community Events
184
Community Groups

IssueLinkCreatedEvent not working as expected

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

1 vote
Alejandro Suárez
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.
Jan 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
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.
Jan 13, 2019 • edited

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.
Jan 08, 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events