Automaticaly creat subtask while creating a task.

Hi ,

I just added a post-function to create sub-task on the create issue --> open transition.

But it not working, mean the sub task wont created.

Could you suggest on this?



5 answers

1 accepted

This widget could not be displayed.

I got the solution. add the postfuction to create sub-task on create issue--> open transition and

Put down the postfuction on last

This widget could not be displayed.

In a lot of cases, this won't work. The issue isn't physically created until the end of the create process, and sub-tasks can only be created on issues that exisit. A lot of create-subtask post-functions will fail because of this.

Which post-function are you using? (I.e. which plugin?) And where exactly have you used the post-fcuntion on the list of post-functions on the transition?

Ok, that's probably going to give you some useful information in the log when you attempt it (something like "parent doesn't exist"). Could you have a look in the log? And tell us where exactly the post-function is used? (Also, confirm that "Testing" is definitely a sub-task type?)

Script workflow function : Create a sub-task.
Subtask will be created with issue type: Testing

yes testing is a aub-task type.

the postfunnction defined on create issue--> open transition

Ok, good, because it will fail if it's the wrong type of task.

Again, as I asked before, could you tell us where you have added the post-function is on the list of post-functions on the transition?

Also, could you have a look at the log?

could you suggest how and where i need to check the log.

i just joined as a fresher. so i m looking this foruim to classroom

This widget could not be displayed.

package com.onresolve.jira.groovy.canned.workflow.postfunctions

import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.workflow.JiraWorkflow
import com.onresolve.jira.groovy.canned.CannedScript
import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
import com.onresolve.jira.groovy.canned.utils.ConditionUtils
import com.onresolve.jira.groovy.canned.utils.WorkflowUtils
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor

class CreateSubTask extends AbstractCloneIssue implements CannedScript{


String getName() {
return "Create a sub-task."

public String getHelpUrl() {

String getDescription() {
return "Create a sub-task. Will optionally reopen a matching sub-task."

List getCategories() {
["Function", "Listener"]

List getParameters(Map params) {
Label:"Target Issue Type",
Type: "list",
Description:"""Target issue type. Leave blank for the same issue type as the source issue.
<br>NOTE: This issue type must be valid for the target project""",
Values: CannedScriptUtils.getAllSubTaskIssueTypes(true),
Label:"Subtask Summary",
Description:"""Optionally set the summary. If blank it will be inherited from the parent.
<br>This is useful in conjunction with automatic reopening of subtasks""",
Label:"Subtask Action",
Type: "list",
Description:"""Optionally set an action that will be applied to a sub-task if a
matching subtask already exists""",
Values: CannedScriptUtils.getAllWorkflowActions(true),

public ErrorCollection doValidate(Map params, boolean forPreview) {
SimpleErrorCollection errorCollection = new SimpleErrorCollection()
errorCollection.addError(FIELD_TARGET_ISSUE_TYPE, "You must provide the target issue type.")
// todo: validation for issue type if set

return errorCollection

Map doScript(Map params) {
MutableIssue issue = params['issue'] as MutableIssue
Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
if (! doIt) {
return [:]

def String subtaskAction = params[FIELD_SUBTASK_ACTION]
subtaskAction = subtaskAction?.replaceAll(/ .*/, "")
String subtaskSummary = params[FIELD_SUBTASK_SUMMARY]
if (issue.getIssueTypeObject().isSubTask()) {
log.warn ("This issue ($issue) is already a sub-task... doing nothing.")
return [:]

// if we have a subtask action, and the subtask exists, and the action is applicable... do it
Collection<MutableIssue> subTasks = issue.getSubTaskObjects()
if (subtaskAction && subtaskSummary && subTasks*.summary.contains(subtaskSummary)) {
subTasks.each {MutableIssue sub ->
if (sub.summary == subtaskSummary) {
if (WorkflowUtils.hasAction(sub, subtaskAction as Integer)) {
try {
// actionIssue(sub, subtaskAction as Integer, WorkflowUtils.getUser(params))
WorkflowUtils.actionIssue(null, sub, subtaskAction as Integer, WorkflowUtils.getUser(params), [:])
catch (Exception e) {
log.error(e.message, e)
else {
log.debug("Action not applicable")
return [:]

params = super.doScript (params)

Issue newIssue = params['newIssue'] as Issue

def subTaskManager = componentManager.getSubTaskManager()
subTaskManager.createSubTaskIssueLink(issue, newIssue, getUser(params))

// GRV-115 - reindex again after creating subtask link


String getDescription(Map params, boolean forPreview) {
ConstantsManager constantsManager = componentManager.getConstantsManager()
StringBuffer sb = new StringBuffer()
sb << getName() + "<br>Subtask will be created with issue type: <b>" +
(params[FIELD_TARGET_ISSUE_TYPE] ? constantsManager.getIssueTypeObject(params[FIELD_TARGET_ISSUE_TYPE] as String)?.name
: "same as parent") + "</b>"

public Boolean isFinalParamsPage(Map params) {

Please look into it . Help me to change this according to how we can create subtask while creating task

This widget could not be displayed.
This widget could not be displayed.

could yoy suggest how and wher i need to check the log.

i just joined as a fresher. so i m looking this foruim to classroom

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