You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I want a set of subtasks created, which are the components of the parent. So, if I have a Parent issue with 3 component names of "X", "A" and "B", then I want 3 subtasks created for that jira.
Here's my code at this point, but it's not working:
(I've put it into a Post-function.)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
def issue = event.issue
Collection components = issue.getComponents();
Iterator componentIterator = components.iterator();
while (componentIterator.hasNext()) {
component = componentIterator.next()
String componentName = component.getString("name");
String componentId = component.getString("id");
createSubtask(issue);
}
def createSubtask(Issue parentIssue) {
def subTaskManager = ComponentAccessor.subTaskManager
def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def constantsManager = ComponentAccessor.constantsManager
def issueService = ComponentAccessor.issueService
def subtaskIssueType = constantsManager.allIssueTypeObjects.findByName("Approval Sub-task")
def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters
.setProjectId(parentIssue.projectId)
.setIssueTypeId(subtaskIssueType.id)
.setSummary(parentIssue.summary+'- **'+componentName)
.setComponentIds(componentId)
//.setDescription('A description')
.setReporterId(asUser.key)
def createValidationResult = ComponentAccessor.issueService.validateSubTaskCreate(asUser, parentIssue.id, issueInputParameters)
if (!createValidationResult.valid) {
log.error createValidationResult.errorCollection
return
}
def newIssue = issueService.create(asUser, createValidationResult).issue
subTaskManager.createSubTaskIssueLink(parentIssue, newIssue, asUser)
}
@Jason Stein This should work. Make sure it's in post-function before "Re-index an issue to keep indexes in sync with the database."
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.user. ApplicationUser
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.project.component.ProjectComponent
def constantManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
Issue parentIssue = issue
if (parentIssue.getIssueType().name == 'Task')
{
Collection components = issue.getComponents();
//def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def data = customFieldManager.getCustomFieldObject('customfield_10488')
//def listq = issue.getCustomFieldValue(data)
components.each {
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setAssigneeId(parentIssue.assigneeId)
newSubTask.setSummary(it.name)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
def newIssueParams = ["issue" : newSubTask] as Map
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
log.info "Issue with summary ${newSubTask.summary} created"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.