I am using use a listener in Jira to execute some code if a specific transition was made. I need to retrieve the transition name to only fire the event if the transition is called "MounaTransition". It seems that the following code is not working to get the transition name in the listener.
import com.atlassian.jira.component.ComponentAccessor
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"] as int).getName()
Here is the code I have written so far in my listener to try to do the same thing that I was doing with the custom post function before. Any idea on how to get the transition name/ID? I can only operate and execute my script if the tranition name matches the one I am interested in.
import org.ofbiz.core.entity.GenericValue
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue;
import java.util.List;
import org.apache.log4j.Logger;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor
import org.ofbiz.core.entity.GenericDelegator;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.WorkflowException;
import com.opensymphony.workflow.loader.StepDescriptor;
import com.opensymphony.workflow.spi.SimpleStep;
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.workflow.ImmutableWorkflowDescriptor
import com.atlassian.jira.web.action.admin.workflow.ViewWorkflowStep
import com.opensymphony.workflow.loader.ActionDescriptor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.IssueValidationResult
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilFactory
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.event.Event
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
def log = Logger.getLogger("atlassian-jira.log")
log.warn("This is the last action ")
Issue issue = event.getIssue();
log.warn("CAM 0 ")
log.warn("CAM 0.1 ")
//Get worklflowname By actionId
GenericValue changeLog = event.getChangeLog();
log.warn("HERE 1")
List<GenericValue> changeItems = ComponentAccessor.getChangeHistoryManager().getAllChangeItems(issue)
// changeItems = changeLog.internalDelegator.findByAnd("ChangeItem", fields);
//changeItems = changeLog
log.warn("HERE 5::: "+ changeItems)
log.warn("MOUNA IS HERE AFTER HERE 5 " +changeItems.size());
log.warn("VALUES 1");
int lastIndex= changeItems.size()-1;
log.warn("CAM 0.2")
ChangeHistoryItem value= changeItems.get(lastIndex) as ChangeHistoryItem;
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
log.warn("GENERIC VALUE "+ transientVars["actionId"] +" ");
def actionName = wfd.getAction(transientVars["actionId"] as int).getName()
log.warn("GENERIC VALUE "+ actionName +" ");
Hmm. I know that the transition name is not recorded in the issue History, just the old and new status names and ids. But actionId is likely what you are looking for. I'm not sure why it is not returning anything for you.