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

How to get the Issue status in IssueLinkCreatedEvent Listener Edited

I have a scenario when an Issue status is in specific status, I have to move from one status to other status by using IssueLinkCreatedEvent listener.

1 answer

1 accepted

0 votes
Answer accepted

I found way to find the Issue status in IssueLinkCreatedEvent.

Thank you!!

 

Here is sample Code:

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
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 com.atlassian.jira.issue.link.IssueLinkImpl
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import org.apache.log4j.Logger
import org.apache.log4j.Level


IssueManager im= ComponentAccessor.getIssueManager();
def event = event as IssueLinkCreatedEvent

log.info("Event Class:"+event.getClass());
log.info("DestinationObject: "+event.issueLink.destinationObject);
log.info("Issue Link :"+event.issueLink);

def destinationObject = event.issueLink.destinationObject

MutableIssue issue=im.getIssueByCurrentKey(destinationObject.key);
log.info("Issue Summary :"+issue.getSummary());
log.info("Issue Type :"+issue.getIssueType().getName());
log.info("Key :"+issue.getKey());


def status=issue.getStatus().getName();
log.info("status: "+status);
def actionId=141 //Status: Manager's Review  
def transitionValidationResult
def transitionResult
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueService issueService = ComponentAccessor.getIssueService()

if(status == "Needs Review" && issue.getIssueType().getName()=="Thread")
{
transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId,new IssueInputParametersImpl())

if (transitionValidationResult.isValid())
{
transitionResult = issueService.transition(currentUser, transitionValidationResult)

if (transitionResult.isValid())
{
log.info("Transitioned issue $issue through action $actionId")
}
else
{
log.info("Transition result is not valid") }
}
else
{
log.info("The transitionValidation is not valid")
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Align

Best Practices in Jira Align

Hello Jira Align customers! In order to better serve you on your journey with Jira Align, the Community team has worked with the Jira Align team to curate the content in this collection to better s...

58 views 0 2
Read article

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