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.
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")
}
}
Recommended Learning For You
Level up your skills with Atlassian learning
Learning Path
Get started with Jira Service Management
These short, self-paced courses will help you get up and running in Jira Service Management in just 90 minutes.
Learning Path
Adopt ITSM practices with Jira Service Management
Use this path to build your IT Service Management knowledge and earn an Atlassian certification.
Setting Up ITSM Projects in Jira Service Management
This training series helps you get started in Jira Service Management quickly with the new ITSM project template.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.