Updating list type custom field with a groovy script don't work in Jira 4.4

Benoit D'Amours February 23, 2012

Hi everybody,

In Jira 4.1.2, we used a groovy script and Atlassian API to update a single select list custom field value using this kind of code (cfCustomFieldDDL is the custom field object, adStd is the issue, "None" exist in the options list):

cfCustomFieldDDL.updateValue(null, adStd, new ModifiedValue(adStd.getCustomFieldValue(cfCustomFieldDDL), "None"), changeHolder);

This was effectively setting the selected item of the drop down list to "None". Now that we just upgrade to Jira 4.4.4, this dont work anymore because the customfieldvalue table (stringvalue field) now store the ID of the string, instead of the string itself. I tried to update the customfield with the ID of the string (supplied either as "12245" or 12245) but this dont work.

Please help, this is blocking for me!

3 answers

1 accepted

1 vote
Answer accepted
Dieter
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 Leaders.
February 23, 2012
Since Jira 4.4 you need to pass an Option object, not the id of the option ss String. You find more information in this answer https://answers.atlassian.com/questions/30084/updating-selectlist-cf-values-changes-from-jira-4-3-to-4-4
Dieter
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 Leaders.
February 23, 2012
So in your example instead of "none" pass optionsManager.findByOptionId(new Long(12245))
Dieter
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 Leaders.
February 23, 2012
0 votes
Benoit D'Amours February 26, 2012

Thank you, it's working now!!

0 votes
Benoit D'Amours February 24, 2012

It make sense, but script runner seems unable to load the requiered packages

import com.atlassian.jira.issue.customfields.option
import com.atlassian.jira.issue.customfields.manager

for the code:

OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
Option oSTCouranteDDL = optionsManager.findByOptionId(new Long(12251));
cfSousTacheCouranteDDL.updateValue(null, adStd, new ModifiedValue(adStd.getCustomFieldValue(cfSousTacheCouranteDDL), oSTCouranteDDL), changeHolder);

I got these errors:

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script9.groovy: 10: unable to resolve class com.atlassian.jira.issue.customfields.manager
@ line 10, column 1.
import com.atlassian.jira.issue.customfields.manager
^

Script9.groovy: 9: unable to resolve class com.atlassian.jira.issue.customfields.option
@ line 9, column 1.
import com.atlassian.jira.issue.customfields.option
^

Script9.groovy: 75: unable to resolve class OptionsManager
@ line 75, column 16.
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
^

Script9.groovy: 76: unable to resolve class Option
@ line 76, column 8.
Option oSTCouranteDDL = optionsManager.findByOptionId(new Long(12251));

Did i miss something?

Dieter
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 Leaders.
February 24, 2012
Add a .* at the end of the import lines to import all classes in the packages com.atlassian.jira.issue.customfields.option and com.atlassian.jira.issue.customfields.manager
Like Ann Kristin likes this

Suggest an answer

Log in or Sign up to answer