How to change custom field from text to Labels

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

1 answer

0 votes

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?

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

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.

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

Thanks Nic,

Now ist working fine to me .

 

Regards,

JItendra

 

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

259 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot