When a user creates an issue that with the summary "Markup Master Task - X issues", I'd like to automatically create X number of SubTasks.
ScriptRunner has an option to create a single sub-task on a transition, but I'm looking for something to create multiple sub-tasks rather than manually add a bunch of separate Post Functions.
Here's what I have so far as a Custom Script Post Function for a Create Issue transition. Any help is appreciated!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def parentIssue = sourceIssue
int numMarkups
doAfterCreate = {
if (parentIssue.getIssueType().getName() != 'Task')
{return}
if (parentIssue.summary.contains("Markup Master Task"))
{
numMarkups = Integer.parseInt(parentIssue.summary);
}
if (numMarkups >= 50)
{
return
}
else
{
def i = 0
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
for (i; i < numMarkups; i++)
{
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Markup" + i.toString())
newSubTask.assignee == parentIssue.assignee
newSubTask.components == parentIssue.getComponents()
newSubTask.setParentObject(parentIssue)
newSubTask.setPriorityId(constantManager.getPriorities().find {
it.getName() == "P2" }.id)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task" }.id) }
}
}
}
Hello,
There's a few other questions up that already cover similar scripts to this:
Let me know if you still need help getting something to work after reading over the answers there. :)
Jenna
Thank you @Jenna Davis! I've referenced both of the answers listed.
Both of the threads use this snippet at the bottom of their scripts, but it's throwing an error for me. Particularly, it's saying the word String is an "unexpected token" Any idea what's causing that?
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user.directoryUser, newIssueParams) subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser) log.info "Issue with summary ${newSubTask.summary} and assignee ${assigneeId} created" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was running into the same error, as i'm not a developer i had to look it up and I found the solution. Code is messed up by the website, this is how the line should look like:
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, community likes to finagle the code a bit. The "<" and ">" are the html encodings for "<" (less-than) and ">" (greater-than).
Nice fix!
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.