Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Automatically Update the labels of sub tasks only if the Story's label is SEO_EMEA or MA_EMEA

Hello all,

 

I would like to request a macro where on the labels are supposed to get updated automatically depending on the labels present on the Story task.

I want the labels to be updated only if the Story has SEO_EMEA or MA_EMEA as one of its label.

1 answer

Hello @sai_kiran

Do you have Script Runner plugin installed in your Jira instance ?

Hello @sai_kiran 

Here is a script you should add as a Listener of type Custom listener with events of type "Issue Updated":

// Listener to synchronise certains to label of certains
// issues type to it's subtasks
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def labelMgr = ComponentAccessor.getComponent(LabelManager)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// List of label to synchronise
def labelsToCopy = ["SEO_EMEA", "MA_EMEA"]

// List of issue type that we apply synchronisation
def issueType = ["Bug", "Story"]

//Filter issue type
if (issueType.any{it == event?.issue.issueType.name})
{
// Get changes of labels
def labelsChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.findAll {it.field == "labels"}


if (labelsChange)
{
//get issue
def issue = event.issue

// Get previous labels
def previousLabels = Arrays.asList(((String)labelsChange.oldstring[0]).split())

// Get new labels
def newLabels = Arrays.asList(((String)labelsChange.newstring[0]).split())

// Filter previous labels
def previousLabelsToVerify = labelsToCopy.intersect(previousLabels)

// Filter new labels
def newLabelsToVerify = labelsToCopy.intersect(newLabels)

// Compute labels to delete
def labelsToDelete = previousLabelsToVerify - newLabelsToVerify

// Compute labels to add
def labelsToAdd = newLabelsToVerify - previousLabelsToVerify

//get subtasks
def subtasks = issue.subTaskObjects

subtasks.each { subtask ->
// get current label of the subtask
def subtaskLabels = labelMgr.getLabels(subtask.id).collect{it.label}
// Delete labels
subtaskLabels -= labelsToDelete
// Add labels
subtaskLabels += labelsToAdd
// Change labels of subtask
labelMgr.setLabels(currentUser, subtask.id, subtaskLabels.toSet(), false, true)
}
}
}

Just configure the two first array:

  • labelsToCopy is is an array of all Labels you want to synchronyse with subtasks
  • issueType is an array of the different issueType that need to be synchronise

If you need all issueType this can be easyly modified (delete first if)

If you need a filter on subtasks issueType create a filter on the subtasks collection.

Regards,

Adrien

Thank you, perfect solution!

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you