Transition Parent Issue when a some customfield in all sub-task was updated

Hi Friends!


There is a way to transition parent when all sub-tasks change the status.


But is it a way to transition parent issue when simple checkbox field with one value are marked in all sub-tasks?
In other words I need to transition parent issue when the checkbox customfield in the last sub-task was updated.

2 answers

Hi friend,

Actually the fast track is not an option for you because this will fast track the issue where the update happen, so in your case the subtask.

You want a custom listener where will listens for Issue Updated events and if the updated issue is a subtask then it should go to the parent, get all it's subtasks and if all of them have selected at least the value you want then it will transit the parent. 

Therefore you custom listener, that listens for an Issue Updated event and for the project/s you want. Now, your script (and for a JIRA v7) will be

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "CheckBox A"}
if (! change) {
    // there was an update issue update but it was not the checkbox therefore do nothing
    return
}

Issue issue = issue

def flag = true
def ACTION_ID = 21 // replace with the action id that you want to transit the parent

// is not a subtask therefore do nothing
if (! issue.isSubTask())
    return

def cwdUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// iterate over the subtasks if at least on of the subtasks has notn the value 'Yes' checked then return false
issue.getParentObject().subTaskObjects?.each {subtask ->
    def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("CheckBox A")
    def cfValue = subtask.getCustomFieldValue(cf)
    if (! ("Yes" in cfValue*.value) || !cfValue) {
        log.debug ("Yes option is not selected for subtask ${subtask.key} or there is no option at all")
        flag = false
    }
}

// it it reaches here means all the subtasks have selected ONLY the value yes for the custom field CheckBox A
if (flag)
    transitIssue(issue.parentObject, ACTION_ID, cwdUser)

// this means that all the subtasks have the value 'Yes' checked, therefore return true and make the transition
def transitIssue(Issue issue, int actionId, ApplicationUser cwdUser) {
    def issueService = ComponentAccessor.getIssueService()

    IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.setSkipScreenCheck(true)

    def transitionOptions= new TransitionOptions.Builder()
        .skipConditions()
        .skipPermissions()
        .skipValidators()
        .build()

    def transitionValidationResult =
        issueService.validateTransition(cwdUser, issue.id, actionId, issueInputParameters, transitionOptions)

    if (transitionValidationResult.isValid()) {
        return issueService.transition(cwdUser, transitionValidationResult).getIssue()
    }

    log.error "Transition of issue ${issue.key} failed. " + transitionValidationResult.errorCollection
}

For you information the checkboxes can have more than one value. So in the script above will check if at least on of the selected values (for each subtask) is Yes then it will transit the parent.

Hope that helps.

Regards, Thanos

Hi Thanos!

Many thanks for your incredible script smile Tomorrow I will check it and come back with the answer.

Hi Thanos!
I still was not able to completely check your great script. Moreover I found a workaround by using of Automation wich allows to transit an issue automaticly by checking a checkbox and then I use post-function from my description.

But I have marked your reply as an answer because I think it will work and someone can use it in the future!

Thanks
See you

You would need to write a customer listener using script runner for doing that.

Check here for some examples: https://scriptrunner.adaptavist.com/4.3.5/jira/listeners.html

-Ravi

Hi Ravi. Thanks for the answer!

So I think I should use Fast-track transition an issue listener.

In this case what do I need to choose as event when sub-task is updated?

Which condition helps me to check that all e.g. customfields_10800 have checkboxes?

Sorry I am not good at script writing smile

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Asked 12m ago in Confluence

What are the resources that you use to learn more about Atlassian Products?

I am gathering information about resources available for Atlassian product knowledge transferring for a presentation in our local Atlassian User Group. I want to group them in four categories From ...

3 views 0 1
View question

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you