This is the example code for a PostFunction to transition a linked Issue in status X to another status of the workflow. Very easy with Adaptavist Scriptrunner. See this code.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor def issueLinkManager = ComponentAccessor.getIssueLinkManager() import org.apache.log4j.Category import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; import com.atlassian.jira.issue.comments.CommentManager; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.MutableIssue def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) log.debug "debug statements" String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller(); WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); log.debug "Original: ${issue.getId()}, ${issue.getKey()}. DETECTED " + issue.getStatusObject().getName(); List<IssueLink> allInIssueLink = issueLinkManager.getOutwardLinks(issue.getId()); for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) { IssueLink issueLink = (IssueLink) inIterator.next(); def linkedIssue = issueLink.getDestinationObject(); log.debug "linked: ${linkedIssue.getId()}, ${linkedIssue.getKey()}. DETECTED " + linkedIssue.getStatusObject().getName(); if (linkedIssue.getStatusObject().getName().equals("STATUS_NAME")) { log.debug "linked Content: ${linkedIssue.getId()}, ${linkedIssue.getKey()}." //We can transition the parent ticket log.debug "start transition" workflowTransitionUtil.setIssue((MutableIssue) linkedIssue); workflowTransitionUtil.setUserkey(currentUser); workflowTransitionUtil.setAction (XX); //Transition ID workflowTransitionUtil.validate(); workflowTransitionUtil.progress(); log.debug "end transition" } }
One thought on “New Groovy PostFunction Transition Linked Issue in STATUS X”