Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

How to add an entry for a Custom Label in a Post Function Script

JIRA v7.4.4, 
ScriptRunner 5.3.5

Using "Clone an issue, and link" to create up to 50 product specific issues, and need to automatically populate a custom label field named "Agile Team" with the team that is responsible for that product area.  Already using Additional issue action" to customize a numbers of fields (Summary, Component, a Cascading Select, Watcher, Assignee) , based on the specific product area,  but cannot find a recipe for populating a Custom Label field. Below is an example of what is already working.



import com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.watchers.WatcherManager

def project30 = issue.getProjectObject()
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def userUtil = ComponentAccessor.getUserUtil()

MutableIssue issue = issue

def projectComponentManager30 = ComponentAccessor.getProjectComponentManager()
def newcomponent30= projectComponentManager30.findByComponentName(project30.getId(), "Ethernet RG")

String SUMMARY_VALUE30 = issue.summary
String newSummary30 = "Security Vulnerability (OEM RG/AP (Inteno)) - "+SUMMARY_VALUE30

def customFieldManager3011 = ComponentAccessor.customFieldManager
def optionsManager3011 = ComponentAccessor.optionsManager
def issueManager = ComponentAccessor.issueManager
def productCat3011 = customFieldManager3011.getCustomFieldObjectsByName("Product Category")[0]
def fieldConfig = productCat3011.getRelevantConfig(issue)
def options = optionsManager3011.getOptions(fieldConfig)
def parentOption3011 = options.find { it.value == "Ethernet RG" }
def childOption3011 = parentOption3011?.childOptions?.find { it.value == "" }
def newValues = [:]
newValues.put(null, parentOption3011)
newValues.put("1", childOption3011)
issue.setCustomFieldValue(productCat3011, newValues)

issue.assigneeId = "rmenakat"
issue.summary = newSummary30
checkLink = {link -> false};


1 answer

0 votes

I believe you will have to use the LabelManager

import com.atlassian.jira.issue.label.LabelManager
def lm = ComponentAccessor.getComponent(LabelManager)
def teams = ["YourAgileTeam"]

lm.setLabels(currentUser,,, teams.toSet(),false,false)

Peter-Dave, Thank you for the response.  I have tried this and received a "cannot find matching method" error. When I executed, I received a "issueId should not be null".  I am not a software developer by training, and have been able to rely on examples others have provided but I will continue to try using your recommendation and reference materials to hit upon a solution.  Here is what I tried:

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

def lm = ComponentAccessor.getComponent(LabelManager)
def teams = ["TeamBeacon"]



Thanks again

I didn't attempt to include all the code you might need.

For example, you need to define and get the current user


def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

Also, I'm assuming you already have issue define in the context binding (if you are doing this in a post function.
If not, then you need to acquire an issue object.

If you are putting this in a create transition post function, then you need to put your post function after the "Create the issue originally" and before the re-Index step.


The following works from my console:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
def issue = ComponentAccessor.issueManager.getIssueObject("JSP-4066")
def lm = ComponentAccessor.getComponent(LabelManager)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
lm.setLabels(currentUser,, 15900, ['test2'].toSet(),false,false)

Appreciate the follow-up  and i did assume not all aspects of the solution was included. I always start from what has been provided then move towards a final solution.  This is the first time I have dealt with Labels and there are not a lot of discussions I could find online pointed me in the correct direction.

Up until now I have not used "def currentUser", but will look to roll into to the script.  

For this use-case, the issue is already created, and this is a post function in a workflow transition. 

Unfortunately my last "programming" was Fortran in 1984, using punch-cards, so I rely heavily on recipes/examples to make things work, 


Thanks again, and I will update this once I have a solution or specific questions.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

81 views 1 2
Read article

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