Trigger "Create a sub-task" from a subtask Edited

Hello,

We have Parent_Issue_#1 working by Workflow_#1 (if workflow maters).

Parent_Issue_#1 has Sub-task_#1. Sub-task_#1 works by Workflow_#2 (if workflow maters).

We have to create a Sub-task_#2 for Parent_Issue_#1.
"Create a sub-task" have to be triggered from Sub-task_#1 on one of its workflow (Workflow_#2) transition.

Result should look like:

Parent_Issue_#1
   └ Sub-task_#1 (creates Sub-task_#2 at one of its workflow transitions)
   └ Sub-task_#2

 

We try to achieve it via ScriptRunner scripted post-function.

How can I point at parent issue to be able to create a sub-task in my case?

 

Edited (removed some code because understood it was wrong).

2 answers

1 accepted

This widget could not be displayed.

Managed to do what i need:

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

def issueFactory = ComponentAccessor.getIssueFactory();
def constantManager = ComponentAccessor.getConstantsManager();
def issueManager = ComponentAccessor.getIssueManager();
def subTaskManager = ComponentAccessor.getSubTaskManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

Issue parentIssue = issue.getParentObject();
MutableIssue newSubTask = issueFactory.getIssue();

newSubTask.setSummary('BOOO-512');
newSubTask.setParentObject(parentIssue);
newSubTask.setProjectObject(parentIssue.getProjectObject());
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user.directoryUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser)

 

Thanks to the code provided by Thanos Batagiannis: https://community.atlassian.com/t5/Answers-Developer-Questions/Hi-Can-any-one-guide-me-how-to-create-Subtasks-in-post-function/qaq-p/493429 

This widget could not be displayed.
Tayyab Bashir Community Champion Oct 25, 2017

Hi, You can do that with Bob Swift - Create on Transition add-on. 
I ScriptRunner doesn't let you create a sub-task from a subtask transition. 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

112 views 2 0
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