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
I got the solution. add the postfuction to create sub-task on create issue--> open transition and
Put down the postfuction on last
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to create subtasks on initial issue create has some tips even if you are not using Create on Transition Plugin for JIRA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Script workflow function : Create a sub-task.
Subtask will be created with issue type: Testing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes testing is a aub-task type.
the postfunnction defined on create issue--> open transition
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.