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,365,459
Community Members
 
Community Events
168
Community Groups

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

Atlassian Community Events