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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,796
Community Members
 
Community Events
184
Community Groups

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

Environment:
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.

Thanks,

Wayne

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")
 issue.setComponent([newcomponent30])

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
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 03, 2019

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,issue.id,agileTeamCf.id, 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"]

lm.setLabels(currentUser,issue.id,16791,teams.toSet(),false,false)  

 

Thanks again

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 03, 2019

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, issue.id, 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
TAGS
AUG Leaders

Atlassian Community Events