Hello everyone,
I have a subtask workflow in which I want to create another subtask under the same parent ticket during a specific transition.
Please see below for an example of the "original" subtask workflow I'd like to create the second subtask from.
Subtask 1: [status 1] --transition 1--> [status 2] --transition 2 {create subtask 2 via post function under same parent ticket}--> [status 3] --transition 3--> [close]
Is this doable?
We already have the JSU and Workflow Essentials plugins, but they only allow auto creation of subtasks off of parents and not from transitions within subtasks. I could create a linked issue, but we would have to use a standard issue type instead of a subtask issue type. We require all tasks under a parent ticket to be subtask issue types which makes linking issues via standard issue types not allowed.
We do not have any additional budget for any paid for plug-ins so any suggestions on how to do this for free would be greatly appreciated.
thanks,
Mike
Hi,
It is possible with a workaround when you have JSU.
Thanks
Hi @Michael
try with this script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issue.getParentObject()
if (parentIssue) {
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("WRITE SOMETHING")
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
// if you know the name of the issue type
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
// if you know the ID of the issue type
//newSubTask.setIssueTypeId(10003)
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Stefano Galati,
Unfortunately the above code is only working within the script editor. Whenever I try to implement it within my workflow(s) no subtasks are created.
Here is the code I input:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issue.getParentObject()
if (parentIssue) {
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Test")
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setIssueTypeId(10223)
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
}
Also if we could get this to work, is there a way in your code to grab the summary of the current issue? I'm also running into an issue where I need to "link" the two subtask together. Is there a way to do that as well?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Michael
I tested the script in my project and it works fine... btw if you want to take the summary you can use
def summary = parentIssue.summary
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Stefano Galati do you know what groovy script editor you are using? I'm using the free groovy script editor within "workflow magic box", which doesn't have all of the same features as script runner does.
I do not receive any errors within my groovy script editor when I test out the code above; however, which I implemented the code as a post function groovy script, there is no subtask created.
Thanks,
Michael
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.