Forums

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

auto create sub-task when sub-task is created

Bunty
Contributor
March 1, 2019

Hello All,

We want to create sub-task automatically when an sub-task is created in parent issue.

For Example:

In our project We have parent issues called Docs and automation and sub-task issues called Development and Testing.

when Development(sub-task) issue created it has to create Testing(sub-task) issue automatically on parent issue. I've added script runner create sub-task post function in Development(sub-task) workflow on create transition and added a condition as shown in the attachment below. the condition was not working.

Could any one suggest me on this...

Thanks in Advance,

Buntypostfunction.PNG

2 answers

0 votes
Bunty
Contributor
March 4, 2019

Hi @Brittany Wispell

I've successfully created the Testing(sub-task) when development(sub-task) issue is created by the below script.

import org.apache.log4j.Category
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

Category log = log
log.setLevel(org.apache.log4j.Level.DEBUG);

def constantManager = ComponentAccessor.getConstantsManager()
def pIssueType1 = constantManager.getAllIssueTypeObjects().find{it.getName() == " Docs"}.id
//def pIssueType2 = constantManager.getAllIssueTypeObjects().find{it.getName() == "Acrolinx"}.id
def parentIssue = issue.getParentObject()
def pid = parentIssue.getIssueTypeId()
log.info(pid)
log.info(pIssueType1)
if (pid.equals(pIssueType1) || pid.equals("10311")) {
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setProjectId(issue.getProjectId())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Testing"}.id)
newSubTask.setSummary("Testing:")
def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
}

0 votes
Brittany Wispell
Community Champion
March 1, 2019

Hey @Bunty 

For the condition:

The condition is not working because you are checking the existing issue if it is a 'Docs' issuetype, which it is not it is the 'Development' issuetype since it is in the 'Development' workflow. 

Have you tried creating both sub-tasks at the same time the way you currently create the 'Development' sub-task? 

You could add to the 'Docs' workflow 2 Create a Sub-task post functions, one that creates the Development and one that creates the Testing sub-tasks. 

Let me know if you have any other questions or need more clarification.

Bunty
Contributor
March 1, 2019

Hi @Brittany Wispell

Yes, I've created both sub-tasks at the same time by adding script runner post function on "Docs" workflow create issue transition.

But, in my scenario i have to create testing sub-task automatically when development sub-task is created in Docs issue type.

How can i add this condition on the "Docs" workflow?

Brittany Wispell
Community Champion
March 1, 2019

Hello again, 

I guess I'm not understanding. 

Which sub-tasks are being created when the 'Docs' workflow is created? 

You should be able to create both sub-tasks from the 'Docs' workflow whenever the ticket is initially created by having 2 post functions.

Below image is how I am visualizing the situation. Is this wrong? 

Screen Shot 2019-03-01 at 12.49.21 PM.png

Bunty
Contributor
March 1, 2019

Hi,

When Docs issue type is created two sub-tasks(Development and Testing) are creating successfully.

But, in my scenario i have to create testing sub-task automatically when development sub-task is created in Docs issue type.

For Example: Parent issue "Docs" already exists in the project. However, Testing(sub-task) has to create automatically when Development sub-task is created manually by the user under "docs" issue type.

Suggest an answer

Log in or Sign up to answer