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

How to get the Issue status in IssueLinkCreatedEvent Listener

DVK April 11, 2020

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

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
DVK April 12, 2020

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")
}
}

TAGS
AUG Leaders

Atlassian Community Events