Behaviour on label field in jira

Hi,

 

I would like to add new labels to label field based on the issue type.

I want to use behaviour plugin to do so.

I already applied this script in a post function on first transition in a workflow (after create):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
  
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(issue.id).collect{it.getLabel()}
labels += 'Incident'
labelManager.setLabels(user,issue.id,labels.toSet(),false,false)

 

 

And it works fine.

But I want this functionality be set as a behavior of a field for few issue type (not associated with specific transition of the workflow, and also updated when the issue is moved to the different issue queue-there will be few categories of the labels depending on issue type, like "incident", "service request", "project"). Can you please advise how I can rewrite this code to be useful as a server site script?

Thanks,

Kasia

1 answer

Hi,

I have looked into this issue it turns out that it is not possible to set the value of the Labels field using the Behaviours module of Script Runner. I have enclosed a screenshot from the Script Runner documentation showing that this is not possible.

labels bug.png

A support ticket has been created for this issue can be viewed at GRV-918.

For the meantime I would suggest you keep using the code above using post functions to add labels. You could use the example if statement code in your post function to check if the issue is of a certain type and if so only add labels for that issue type.

// Repeat the if statement for each issue type that needs to be checked for
if (issue.issueTypeObject.name == "Task"){
// Add Label code here
}

I hope this helps

Kristian

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

849 views 2 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you