Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-create a subtask within a parent ticket via a transition within another subtask

Michael
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.
March 11, 2020

Hello everyone,

I have a subtask workflow in which I want to create another subtask under the same parent ticket during a specific transition.

Please see below for an example of the "original" subtask workflow I'd like to create the second subtask from.

Subtask 1: [status 1] --transition 1--> [status 2] --transition 2 {create subtask 2 via post function under same parent ticket}--> [status 3] --transition 3--> [close]

Is this doable?

We already have the JSU and Workflow Essentials plugins, but they only allow auto creation of subtasks off of parents and not from transitions within subtasks. I could create a linked issue, but we would have to use a standard issue type instead of a subtask issue type. We require all tasks under a parent ticket to be subtask issue types which makes linking issues via standard issue types not allowed.

We do not have any additional budget for any paid for plug-ins so any suggestions on how to do this for free would be greatly appreciated.

thanks,

Mike

2 answers

1 accepted

1 vote
Answer accepted
Partibha Rani
Contributor
March 11, 2020

Hi,

It is possible with a workaround when you have JSU. 

  1. Configure a Create Linked Issue PF in the Parent Issue transition which is a hidden transition and available to some dummy user with a condition.
  2. On Sub-Task, configure Linked transition to perform transition on Parent issue as a dummy user.  If you are still having difficulty in configuration, please contact to our support on https://servicedesk-apps.beecom.ch/servicedesk/customer/portal/3.

Thanks

0 votes
Stefano Galati March 12, 2020

Hi @Michael 

try with this script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issue.getParentObject()
if (parentIssue) {
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("WRITE SOMETHING")
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())

// if you know the name of the issue type
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
// if you know the ID of the issue type
//newSubTask.setIssueTypeId(10003)

Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
}
Michael
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.
March 18, 2020

Hello @Stefano Galati,

 

Unfortunately the above code is only working within the script editor. Whenever I try to implement it within my workflow(s) no subtasks are created.

 

Here is the code I input:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issue.getParentObject()
if (parentIssue) {
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Test")
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setIssueTypeId(10223)

Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
}

Also if we could get this to work, is there a way in your code to grab the summary of the current issue? I'm also running into an issue where I need to "link" the two subtask together. Is there a way to do that as well?

Stefano Galati March 19, 2020

Hi @Michael 

I tested the script in my project and it works fine... btw if you want to take the summary you can use

def summary = parentIssue.summary
Michael
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.
March 19, 2020

Hi again @Stefano Galati do you know what groovy script editor you are using? I'm using the  free groovy script editor within "workflow magic box", which doesn't have all of the same features as script runner does.

I do not receive any errors within my groovy script editor when I test out the code above; however, which I implemented the code as a post function groovy script, there is no subtask created.

Thanks,

Michael

Suggest an answer

Log in or Sign up to answer