Hi,
Is there a way to have the scriptrunner plugin clone all the subtasks when using "clone issue and link" post-function?
Regards
Conor
Hi Conor,
It is possible, writing your own script in the Additional Issue actions.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.user.ApplicationUser import groovy.transform.Field Field ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() @Field MutableIssue cloneIssue = issue Issue originalIssue = sourceIssue def subtasks = originalIssue.getSubTaskObjects() // if there are no subtasks to clone, do nothing if (!subtasks) return doAfterCreate = { subtasks.each {subtask -> def summary = subtask.getSummary() def assignee = subtask.getAssignee() def descr = subtask.getDescription() def textFieldA = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("TextFieldA") def textFieldAValue = subtask.getCustomFieldValue(textFieldA) createSubTask(summary, assignee, descr, textFieldAValue) } } def createSubTask(String summary, ApplicationUser assignee, String description, def customFieldValue) { def issueFactory = ComponentAccessor.getIssueFactory() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() def subTaskManager = ComponentAccessor.getSubTaskManager() def textFieldA = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("TextFieldA") MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary(summary) newSubTask.setAssignee(assignee) newSubTask.setDescription(description) newSubTask.setCustomFieldValue(textFieldA, customFieldValue) newSubTask.setParentObject(cloneIssue) newSubTask.setProjectObject(cloneIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find { it.getName() == "Sub-task" }.id) Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user, newIssueParams) subTaskManager.createSubTaskIssueLink(cloneIssue, newSubTask, user) log.info "Subtask ${newSubTask.getKey()} created" }
regards,
Thanos
Hi Thanos, this is what I have in the Additional issue actions so far, but I'm struggling. Could you please assist? many thanks
import com.atlassian.jira.issue.Issue import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Logger # Get subtasks of ORIGINAL parent issue def subTaskList = issue.getSubTaskObjects() // Iterate through the subtasks for (subTask in subTaskList) { def subtaskAssignee = subTask.assignee.displayName def subtaskSummary = subTask.summary def subtaskDescription = subTask.description # How do I get the newly cloned parent issue to attach these new subtasks to? # Once I get this new parent issue can I run a REST API curl command like below to create the new subtasks for the newly cloned parent? # How do i get current username|password to run command curl -D- -u $USER:$PASSWORD -X POST -H "Content-Type: application/json" https://ourjira/rest/api/2/issue --data '{"fields":{"project":{"key": "DEMO"},"parent":{"key": "'$NEW_PARENT'"},"summary": "'subtaskSummary'","description": "'$subtaskDescription'","issuetype":{"id": "44"},"assignee":{"name":"'$subtaskAssignee'"}}}' }
Sorry I was not clear enough and just realised that the way is not documented. Therefore I edited my answer above adding a script. Is not thoroughly tested therefore recommend you to try it in a test system first.
regards
UPDATE:
Link to the updated documentation After Create actions
It looks like you're new here. Sign in or register to get started.