Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×I've written a post function via scriptrunner to create subtasks. I've managed to copy over standard jira fields like priority, summary etc.. to the subtask but am finding it difficult to copy the custom field over. This is my code below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Logger
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
Issue parentIssue = issue.getParentObject()
IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
// user admin is allowed to create a new ticket
def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext
def user = jiraAuthenticationContext.loggedInUser
// Required to create tickets
IssueManager issueManager = ComponentAccessor.getIssueManager()
// FOR REA
// Find the id of the systemtest subtask
String REAsubTaskId = ComponentAccessor.getConstantsManager().getAllIssueTypeObjects().find{it.getName() == "Axon Delivery - Realisation subtask"}.id
// Fill subtask parameters
MutableIssue REAnewSubTask = issueFactory.getIssue()
REAnewSubTask.setSummary("REA - bugfix (ST NOK)")
REAnewSubTask.setDescription("REA - see previous ST-subtask for description")
REAnewSubTask.setParentObject(parentIssue)
REAnewSubTask.setProjectObject(parentIssue.getProjectObject())
REAnewSubTask.setIssueTypeId(REAsubTaskId)
REAnewSubTask.setPriority(parentIssue.getPriority())
REAnewSubTask.setReporter(parentIssue.getReporter())
// Add any other fields you want for the newly created sub task
Map REAnewIssueParams = ["issue" : REAnewSubTask] as Map
def REAcreatedSubtask = issueManager.createIssueObject(user, REAnewIssueParams)
// Link created subtask to parent
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, REAcreatedSubtask, ComponentAccessor.jiraAuthenticationContext.getLoggedInUser())
Could someone enlighten me please?
hi @Keylane ICT I'm using setCustomFieldValue function, so for you it could be:
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customFieldId = 1111L // you have to put your ID here
def customField = customFieldManager.getCustomFieldObject(customFieldId)
REAnewSubTask.setCustomFieldValue(customField, parentIssue.getCustomFieldValue(customField))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.