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 "+issue.projectObject.name+" 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

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

Advertisements
Posted by:.

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s