Script Runner - Create a SubTask

Before I start, my apologies if this seems a bit long-winded...

I need to create some testing sub-tasks with Approve/Reject actions to acknowledge testing in specific environments when an issue is ready for test. Once all sub-tasks have been done, it should move the parent issue to approved status or if any of the tests fail, the parent issue should be moved to a reject status and then back into development for fixing. My use case is actually similar to the use case discussed in the script runner documentation but am not quite able to understand the implementation as described here:

https://scriptrunner.adaptavist.com/4.3.5/jira/builtin-scripts.html#_create_a_sub_task

My workflow looks like:

image2016-10-27 11:13:31.png

And I am creating a transition step on pass testing but am kinda clueless how to go about adding Approve, Reject, Reopen steps in it...

image2016-10-27 11:11:49.png

 

When my sub-tasks get created, they all get set to an OPEN status initially. Just wondering how I can have the approve & reject options next to each sub-task rather than open status... What am I missing???

image2016-10-27 11:23:24.png

 

Ideally, I would like to see something like in the documentation:-

image2016-10-27 11:27:16.png

Looking for some how-tos please, if possible...

 

Thanks

1 answer

Hi Anupam

If I understand right you want to create a subtask and immediately to tansit it to a status. So let's say that you want when the subtask with summary Run IST Testing get's created to immediately move through the Pass Testing transition then in the post function you have that creates the subtask Run IST Testing in the additional issue actions field add 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
doAfterCreate = {
    
    def cwdUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    def issueService = ComponentAccessor.getIssueService()
    IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.setSkipScreenCheck(true)
    log.debug "I will transit the subtask " + issue.key
    def transitionOptions= new TransitionOptions.Builder()
        .skipConditions()
        .skipPermissions()
        .skipValidators()
        .build()
    // 21 is the id of the transition, in my example is the In Progress (21). Change it to fit your transition
    def transitionValidationResult =
        issueService.validateTransition(cwdUser, issue.id, 21, issueInputParameters, transitionOptions)
    if (transitionValidationResult.isValid()) {
        return issueService.transition(cwdUser, transitionValidationResult).getIssue()
    }
    log.error "Transition validation result: " + transitionValidationResult.errorCollection
}

Please let me know if this does the trick 

regards, Thanos

Hi Thanos,

Thanks for your response. I tried it out but it is still not working as expected. The subtasks should not stay open when the parent issue is done. Also, the problem is that for the sub tasks, I don't see the action Approve or Reject. It is still showing the transitions as per my workflow for Open Status - Please see attached screenshot.

image2016-10-27 16:42:54.png

image2016-10-27 16:43:10.png

image2016-10-27 17:3:9.png

The sub-tasks only need to have two transition actions. Approve and Reject.

What I am trying to do is as follows:

  1. Assignee moves Issue into "Ready for Test"
  2. Once issue is in this status, there should be new sub-tasks created for that issue automatically -
    Sub Task 1: Run DEV Testing
    Sub Task 2: Run IST Testing
    Sub Task 3: Run UAT Testing
  3. These sub-tasks should have only two transition actions to chose from - Approve and Reject
  4. Once all these subtasks are approved, the parent issue can move automatically to Approved Status. If however, any one of these sub-tasks get rejected, the parent issue can move to Rejected Status automatically. The parent issue can also be moved manually if it is not possible to automate that...
     

So in theory, it is similar to your documentation use case...

image2016-10-27 16:55:13.png

Notice how it has Approve & Reject actions. I am looking to implement the similar logic. I hope that helps understand my use case better.

Thanks

Anupam

 

 

Hi, Anupam.

So, there's a lot of layers to what you're after. I think I can get you over the immediate road blocks, though.

  1. Why are the sub-tasks staying in the "Open" state? The answer, based on the screenshot you provided of your workflow, is that to get to the point where the subtasks have a step leading to "Approved" or "Rejected", your workflow requires them to go through the In Progress status, then undergo the "Test" transition. There are two ways you might work around that. First (and most simply), you could create a workflow just for your subtasks. One advantage of this approach is that you could have different transition names (like Approve/Reject) than your parent tasks have.
    Alternately, you could just transition your sub-task through all the statuses between "Open" and "Ready for Test" in the Additional Actions code. That's a bit more cumbersome, and it will mean your available transitions will be "Pass Testing" and "Fail Testing", not "Approve" and "Reject". Still, it might be suitable if you really don't want to have a separate workflow for sub-tasks.
    1. You also hinted at a related issue. You may be wondering why the actions available to your sub-task aren't listed on the parent issue. That screenshot you listed is from an earlier version of JIRA. To see the transitions available to a subtask from a parent issue, you have to click the little gear next to them.
  2. You also wrote, "The subtasks should not stay open when the parent issue is done". How to address that depends on your needs. On the one hand, you could use the built-in JIRA feature that doesn't let you close a parent task until all sub-tasks are marked as done. On the other, you could setup a separate post-function to automatically close the sub-tasks of a parent issue. See the documented example at
    https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/auto-close-all-subtasks.html 

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

26,228 views 2 7
Join discussion

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