How to change custom field from text to Labels

Adhikari Jitendra Kumar Das May 30, 2017

Hi ,

As per my project requirement i have changes the custom field from text to Labels, While i am updating the values of custom filed i am getting groovy script error. Please suggest what could be the approch.

Error Stack :

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Set
at com.atlassian.jira.issue.customfields.impl.LabelsCFType.createValue(LabelsCFType.java:79)

 

Code: 

CustomField cfEcpId = cfManager.getCustomFieldObjectsByName("ECP ID Label").first();

cf.updateValue(fieldLayoutItem, issue, new ModifiedValue(currentValue, newValue), new DefaultIssueChangeHolder());

 

Regards,

JItendra

2 answers

0 votes
Chase B. June 7, 2018

@Adhikari Jitendra Kumar DasI am interested in getting the code for this... I'm assuming you are running it in the Script Console?

 

I had come up with a solution that will effectively accomplish my intent over time with this post: https://community.atlassian.com/t5/Jira-Core-questions/ScriptRunner-Listener-Copy-free-text-custom-field-value-into-a/qaq-p/743690 

However, being able to copy the free text values over to the new label field without having to wait for user-generated events would be amazing as some of our issues may never be edited. 

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.
May 30, 2017

You can't just change a field from one type to another.

Do you mean you have  a label field that you are trying to copy some text into from another field?

Adhikari Jitendra Kumar Das May 30, 2017

Hi,

Its not exactly changeing from one field to other , its like i am creating a new field with Lebel type and while processing through groovy script but not able to update the value .

Regard,

JItendra

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.
May 30, 2017

Ah, good, that's the right way to approach it.

The problem you have is that your script is not pushing the right type of data into the label field.

A string field is a string of letters.  A label field is a collection of individual labels, each of which holds a string that is the name of the label.

In your code, the "newValue" going into the changeHolder needs to be a collection of labels.  You'll need to read out the existing labels as a collection, then take the string you want to add to them, convert it into a set of labels you add to that collection, and post that back.

Adhikari Jitendra Kumar Das May 30, 2017

Thanks Nic,

Can you help me with sample code if you have , I just want to update the custom field of Label type with certain value(Issue key).

I am not sure how to achieve this with labelmanager api or cf.updateValue method .

 

Regards,

JItendra

Adhikari Jitendra Kumar Das June 1, 2017

Thanks Nic,

Now ist working fine to me .

 

Regards,

JItendra

 

Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2018

Hi @Adhikari Jitendra Kumar Das,

Could you please share a sample code which is working for you? I have a similar requirement..

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events