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

Peddinti Hemanth Satyakumar October 7, 2018

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

Suggest an answer

Log in or Sign up to 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.
October 8, 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.

TAGS
AUG Leaders

Atlassian Community Events