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.

Captura de pantalla 2019-03-24 a las 13.14.47

We can use the “Create Sub-task” script Postfunction with the usual parameters…

Captura de pantalla 2019-03-24 a las 13.15.59


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 "" task with name " + sourceIssue.summary
doAfterCreate = {
def labelManager = ComponentAccessor.getComponent(LabelManager)
labelManager.addLabel(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue.getId(), "TASK_LABEL", false)

Captura de pantalla 2019-03-24 a las 13.17.40


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

Posted by:.

One thought on “Create sub-task with specific label with Scriptrunner and Jira Server

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s