Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

using script runner can to update labels from a text in the summary

Edited

hi

i have jira auto create tickets with summary as below

[DEPLOYMENT] test_putinlabels uuuuu

I want to update a labels with the text test_putinlabels.

can we do this as a post function and if yes what is the code

2 answers

Suggest an answer

Log in or Sign up to answer

hi all 

i figured this out with the help of someone but can someone explain why we have to use print for this to work my code is below 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def user = ComponentAccessor.jiraAuthenticationContext.getUser()

def summary = issue.summary
print(summary)

if (summary.startsWith("[test]"))
{
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(issue.id).collect{it.getLabel()}
def newlabel = summary.split(" ")[1]
print(newlabel)
labels += newlabel
labelManager.setLabels(user.getDirectoryUser(),issue.id,labels.toSet(),false,false)
}

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 02, 2017 • edited

Yes, you can do that with a script.

The snippet I have is

 import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def user = ComponentAccessor.jiraAuthenticationContext.getUser()

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

That code just sets the labels, you'll need to code "issue.summary to list of labels to add" for yourself.

ignore this let me try that

somethingblue
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jun 09, 2017

Hi Kaushal,

Hopefully the script Nic provided worked out for you.  If so please mark his answer as Accept Solution so others may benefit from the solution as well!

Cheers,

Branden

hi 

i dont understand how to get the information for the summary and add it to the label. not dont much coding before. is there any guides i can follow to help with this part 

TAGS
AUG Leaders

Atlassian Community Events