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,361,259
Community Members
 
Community Events
168
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

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
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

205 views 1 6
Read article

Atlassian Community Events