Usually we want to create automatically subtasks in a transition and sometimes with a specific label. We use usually the plugin Adaptavist Scriptrunner in Jira Server to do tasks like this. Just creating a Postfunction in the Workflow.
We can use the “Create Sub-task” script Postfunction with the usual parameters…
In the “additional issue actions” section add something like this
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.label.LabelManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.ApplicationUser def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() issue.summary = "Project "+issue.projectObject.name+" task with name " + sourceIssue.summary doAfterCreate = { def labelManager = ComponentAccessor.getComponent(LabelManager) labelManager.addLabel(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue.getId(), "TASK_LABEL", false) }
IMPORTANT NOTE:
Usually when we add a label the ticket must be created previously, for this reason the problem should be the “additional code” section runs before the issue is actually created.
You could try to put in the code in a “doAfterCreate” closure the “add label part“:
doAfterCreate {
// add label
}
By MrAddon
One thought on “Create sub-task with specific label with Scriptrunner and Jira Server”