Automaticaly creat subtask while creating a task.

rajesh174u November 24, 2013

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?

Regards,

Rajesh

5 answers

1 accepted

0 votes
Answer accepted
rajesh174u November 25, 2013

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

Put down the postfuction on last

0 votes
rajesh174u November 25, 2013

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

0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
November 24, 2013
0 votes
rajesh174u November 24, 2013

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{

public static final String FIELD_SUBTASK_SUMMARY = 'FIELD_SUBTASK_SUMMARY'
public static final String FIELD_SUBTASK_ACTION = 'FIELD_SUBTASK_ACTION'


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

public String getHelpUrl() {
"https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Createasubtask"
}

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

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

List getParameters(Map params) {
[
ConditionUtils.getConditionParameter(),
[
Name:FIELD_TARGET_ISSUE_TYPE,
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),
],
[
Name:FIELD_SUBTASK_SUMMARY,
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""",
],
getOverridesParam(),
[
Name:FIELD_SUBTASK_ACTION,
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()
if (!params[FIELD_TARGET_ISSUE_TYPE]) {
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
reindexIssue(newIssue.genericValue)

params
}


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>"
sb.toString()
}

public Boolean isFinalParamsPage(Map params) {
true
}
}

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

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2013

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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2013

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?)

rajesh174u November 24, 2013

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

rajesh174u November 24, 2013

yes testing is a aub-task type.

the postfunnction defined on create issue--> open transition

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2013

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?

rajesh174u November 25, 2013

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

Suggest an answer

Log in or Sign up to answer