Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Updating Select list type custom field value from Null to a given option using groovy

Sumit Kumar
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.
October 17, 2013

Want to update a select list type custom field vaule from null to a string (Should be one of the options from custom field} using groovy.

def changeHolder = new DefaultIssueChangeHolder();

officeRegion.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(officeRegion), officeRegionValue),changeHolder)

officeRegion --- Custom Field

issue --- Issue

officeRegionValue ----- New Value

is there any error in the above code or any event is needed to be fired to see the changes on UI ?

Thanks in advance,

Sumit

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
John Bishop
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.
October 17, 2013

I believe that you cannot set a select list to a string value. You need an object of type Option of the option you want to set the select list to.

In your call to the ModifiedValue constructor, the second parameter needs to be the Option object of the desired value.

In case you don't know how to get the option object, you can use the findByOptionValue method of the OptionsManager(https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/customfields/manager/OptionsManager.html).

0 votes
Sumit Kumar
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.
October 17, 2013

I am able to see the changes now .. thanks Guys .. !!!

0 votes
Sumit Kumar
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.
October 17, 2013

I tried it .. is there anything needed to be done after the values are changed ... as even for my code the values are getting upadted on the first run but I am not able to see the changes on UI.

I dont want to restart the system to get the changes done

0 votes
RambanamP
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.
October 17, 2013

something you need to try like this

CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
Options options = WebAppsCf.getOptions(null, customField.getRelevantConfig(issue), null);
Option newOption = options.getOptionById(newOptionId);
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption );
customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

check this

https://answers.atlassian.com/questions/189262/how-do-i-programmatically-set-values-for-custom-fields-of-type-select-when-creating-an-issue

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events