The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
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