It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Parent Issue status to be updated when all sub-tasks status is updated to same

Hello ,

Below you can find workflow we are using for parent issues and sub-task issue . We have multiple sub-tasks for single parent issue when all sub-tasks status is "Ready FOR RFP" then parent status has to be updated with that status .  In this way once all sub-task's status are updated to now automatically parent issue hast to update with that status.

 

Can anyone guide me with the right script to achieve this task as we have only option to use script runner only.

 

Regards,

Mahesh

Sys adi workflow.JPG

1 answer

Hello,

I have adapted one of the script I use.

 

You should change the name of the transition and verify the name of the status of subtask (the name is: if at least one subtask is still at this status do not transition the parent issue).You need to put this as a post-function of the subtask workflow on the transition between "waiting for cm" and "ready for rfp".

 

If the transition of the parent fail for any reason, the subtask will still make the transition. Some change at the end is needed if you want it to make error instead.

 

//Usage: in post-function of subtask transition
// Transition parent of issue according to the status of subtask,
// if the transition of parent fail the transition of current subtask will works

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueService = ComponentAccessor.issueService
def issueLinkManager = ComponentAccessor.issueLinkManager

// Name of the transition of Parent
final String transitionName = "Ready"

// Name of status in subtask that block transition of parent
final String subTaskStatus = "Waiting for CM"

// Get parent object
def parent = issue.getParentObject();

// Get all subtask of parent
def subtasks = parent.getSubTaskObjects();

// Get subtask that are in status blocking transition of parent
def filteredSubtasks = subtasks.findAll {it.status.name == subTaskStatus}

// If there are still subtask other than current one in an other state do nothing
if (filteredSubtasks - issue)
{
return
}

// Else transition parent issue

def workflowActionId = ComponentAccessor.workflowManager.getWorkflow(parent).allActions.findByName(transitionName)?.id

def issueInputParameters = issueService.newIssueInputParameters()

def transitionValidationResult = issueService.validateTransition(currentUser, parent.id, workflowActionId, issueInputParameters)
if(transitionValidationResult.isValid())
{
issueService.transition(currentUser, transitionValidationResult)
}

 Hope it helps,

 

Adrien

@SITTER_Adrien 

 

I highly appreciate for your quick response let me test this on my workflow .

One more question do we need to implement this on every transition's ?

If you want to do at all transition yes.

Be careful this code works only because it is the first transition of the workflow. You have to change the filtering condition if you want to make it work at an other transition.

This code is looking for any subtask that is in "Waiting for CM", if there is at least one it does not make the transition of the parent.


But if you want for exemple to make it for the transition between "bafo in the market" and "bafo in analysis" you need to select every subtask that are between "Waiting for a CM" and "bafo in market" included.

May be there is a way to compute it using the workflowManager the easiest way is still to write all of them with a collection in the code. But this means than any modification in the workflow will need to make change in every postfunction.

Ok I took it like a challenge. I tested this code and this should work, you just have to copy and past it in a post function for every transition of the workflow.

This should be the last post function, be careful to put it at the bottom list, if it is executed too early this will not work.

This code assume different thing, and it will not work if assumption are not meet, it will certainly create infinite loop if assumption are not respected. THose assumption are:

Subtask and parent have the same workflow

Workflow must be linear.

  • No split : no transition from one status to 2 or more status. Every status can have one and only one transition coming from it and one and only one transition going out of it. Inlucding creation transition.
  • No loop : this should not be the case if you respect no split.

 

//Usage: Transition parent with the current subtask if every subtask has at least reach the same statut.
// Warning: Subtask and parent must have the same workflow.
// Warning : Workflow must be linear: no split, no merge, no loop
// Transition parent of issue according to the status of subtask,
// if the transition of parent fail the transition of current subtask will works

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueService = ComponentAccessor.issueService
def issueLinkManager = ComponentAccessor.issueLinkManager

// Workflow manager and descriptor
def wf = ComponentAccessor.workflowManager.getWorkflow(issue)
def wfd = wf.descriptor

// Compute the current transition
final String transitionName = wfd.getAction(transientVars['actionId']).name

// Compute the list of statut for which if at least one subtask is in, the transition should not be done
def allAction = wf.getAllActions()
def currentAction = allAction.find{wf.isInitialAction(it)}
def currentStep = wfd.getStep(currentAction.getUnconditionalResult().step);
def currentStatusName = currentStep.name
def forbidStatus = []


while (currentStatusName != issue.status.name)
{
forbidStatus.add(currentStatusName)
currentAction = currentStep.actions[0];
currentStep = wfd.getStep(currentAction.getUnconditionalResult().step)
currentStatusName = currentStep.name
}

// Get parent object
def parent = issue.getParentObject();

// Get all subtask of parent
def subtasks = parent.getSubTaskObjects();

// Get subtask that are in status blocking transition of parent
def filteredSubtasks = subtasks.findAll {it1 -> forbidStatus.any{ forbid -> forbid == it1.status.name}}
// If there are still subtask other than current one in an other state do nothing
if (filteredSubtasks)
{
return
}

// Else transition parent issue

def workflowActionId = ComponentAccessor.workflowManager.getWorkflow(parent).allActions.findByName(transitionName)?.id

def issueInputParameters = issueService.newIssueInputParameters()

def transitionValidationResult = issueService.validateTransition(currentUser, parent.id, workflowActionId, issueInputParameters)
if(transitionValidationResult.isValid())
{
issueService.transition(currentUser, transitionValidationResult)
}  

 I tested with a linear workflow composed of 4 statut.

 

I hope it will meet you needs,

 

Adrien

Like Mahesh Kallepalli likes this

@SITTER_Adrien 

 

I highly appreciate for spending some time on this let me work on this code and will update you soon .

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you