Script Runner Transition linked parent issue based on status

Josh Costella April 21, 2016

We need to be able to transition a linked parent issue based on the status of the child. We are not using a sub-task.

How can I incorporate the transition to review link type? I've created a combination of a condition script we use for links and then a transition script we use. I know this won't work in it's current state but am I even close? @Jamie Echlin [Adaptavist]

Summary of what we're trying to do:

If linked issue (child link) is transitioned to Defect status, transition parent linked issue to Triage status.

// Required Imports
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def linkType = ["Dependency"]
def passesCondition = true
def linkMgr = ComponentAccessor.getIssueLinkManager()
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
   if (linkType.contains(link.issueLinkType.name)) {
       if (! link.destinationObject.resolutionId) {
           passesCondition = false 

       }
   }
}
return passesCondition

    // Get the details of the user executing the workflow transition for the issue change history
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)

MutableIssue parent = issue.getIssueLink("Dependency") as MutableIssue

    // Get the status name of the parent issue  
String originalParentStatus = parent.status?.name

def isParentTesting = originalParentStatus in ['Testing']

    // Update the issue by validating the transition can be completed first before executing it.
if (isParentTesting) {
    workflowTransitionUtil.setIssue(parent)
    workflowTransitionUtil.setUserkey(currentUser)
    workflowTransitionUtil.setAction(71) // 71 is the ID of the Triage transition on the Story workflow
    if (workflowTransitionUtil.validate()) {
        workflowTransitionUtil.progress()
    }       
}

6 answers

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2016

It will be fine if you write the condition safely. It should not cause other post-functions to fail anyway IIRC. You can always put it in try/catch...

0 votes
Josh Costella April 21, 2016

@Jamie Echlin [Adaptavist], I'm concerned because this is technically a combination of a condition script and post-function. This will be used as a post-function so I want to make sure the condition portion won't cause this to fail.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2016

So you just need to follow the link from child to parent - I'm not sure which bit you're stuck with, you seem to have most of the relevant code.

0 votes
Josh Costella April 21, 2016

@Jamie Echlin [Adaptavist] - When = The linked issue (child) is transitioned to a certain point in its workflow. This would then transition the linked parent issue to a certain point it its workflow.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2016

@Chander Inguva - you're not waiting, we answered it.

@Josh Costella - when do you want this to happen? As we said to Chander, it's not possible to trigger it based on a link being added, but you could trigger it on state change or something.

0 votes
Chander Inguva
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2016

I asked the same question couple of weeks ago https://answers.atlassian.com/questions/38380360

 

  • Still waiting on that

 

Regards

Chander

 

Suggest an answer

Log in or Sign up to answer