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,559,882
Community Members
 
Community Events
185
Community Groups

How to update custom field Label manger field Null values to label type value for multiple issues?

Hi, I'm trying to update multiple issues based on JQL query, for fields which are null values to value ['None'] is it possible to change the null value to label type ['None'] value? when I run the code I'm getting log error as shown in the screenshot. I'm new to the groovy script and I implemented this code by searching the internet. please help me in this I got struck here from long.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Logger

def log = Logger.getLogger("com.acme.workflows")

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def query = jqlQueryParser.parseQuery("category = Projetcategory and \"Shared Labels\" is EMPTY")

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
results.getIssues().each {documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Shared Labels"}
def String newValue = "[None]"
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), newValue), changeHolder);
}

Selection_056.png

 

1 answer

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.
Oct 08, 2018

The second line of the error is something you are going to see a lot.

You have not realised that the field you are trying to put values into is multiple entry field (you can select 0, 1 or many options for it).  This means you have to give it a list of options to store.

The error "java.lang.string cannot be cast to java.util.set" is saying that you can't "cast" between what you've given it and what input it requires.  Casting is "changing the variable type from one to another".

You'll need to build an empty Set and feed that to the changeholder instead of a string.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events