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

TSD Group February 3, 2017

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

2 votes
Thanos Batagiannis _Adaptavist_
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.
February 3, 2017

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

TSD Group February 5, 2017

Hi Thanos!

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

TSD Group April 7, 2017

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

0 votes
Ravi Sagar _Sparxsys_
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.
February 3, 2017

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

TSD Group February 3, 2017

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