Inserting a string into a single select custom field

Jon Sword
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.
November 1, 2011

Hi,

I am trying to set a single select field using a text string from another source. Here is the code I have thus far:

def cfFixDeploymentType = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Fix Deployment Type'};

CustomFieldType customFieldType = cfFixDeploymentType.getCustomFieldType();

newissue.setCustomFieldValue(cfFixDeploymentType, customFieldType.getSingularObjectFromString("Design"));

issueMgr.createIssue(currentUserObj, newissue);

Not sure what I am missing here...

The customFieldType.getSingularObjectFromString is returning "null" if I log it.

customFieldType returns com.atlassian.jira.issue.customfields.impl.SelectCFType@253af1c3 if I log it.

There is a "Design" option associated with the select list.

Running on JIRA 4.4

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
JamieA
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.
November 1, 2011

This will be related to http://confluence.atlassian.com/display/JIRA/Plugin+Developer+Notes+for+JIRA+4.4#PluginDeveloperNotesforJIRA44-Single-andMulti-SelectCustomFieldChanges

Design must be a valid option in the target custom field.

Add some code like this (this is just a pointer, I don't expect this to work ootb):

FieldConfig fieldConfig = cfTarget.getRelevantConfig(issue)
Option o = optionsManager.getOptions(fieldConfig)?.find{it.toString() == "Design"}
issue.setCustomFieldValue(cfTarget, o)

Jon Sword
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.
November 2, 2011

Hi Jamie,

Works like a charm... Thank you!

The only extra changes I had to make were to add the includes and to instantiate the OptionsManager.

Cheers

Bastien
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.
March 13, 2013

Hi,

I try to do the same but in my case, I want to get the customfield's value from an issue and put it in another issue (same type), in the same customfield.

Here my code :

CustomField customField = customFieldManager.getCustomFieldObject("customfield_10905")
Object fromValue = currentIssue.getCustomFieldValue(customField);				
OptionsManager optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
FieldConfig fieldConfigTarget = customField.getRelevantConfig(childIssue)
Option newValueTarget = optionsManager.getOptions(fieldConfigTarget)?.find{it.toString() == fromValue} childIssue.setCustomFieldValue(customField, newValueTarget)

But it doesn't work. No exception, but no setted value in the "childissue". (this code is executed during post function in the "currentIssue")

JamieA
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.
March 16, 2013

I'd ask a new question, I'm not sure this is related.

0 votes
Suresh November 30, 2011

I did like this.I got the option id from that i have set the option value as below

Option opt = optionManager.findByOptionId(Long.valueOf(logConvert));

<font style="font-size: x-small;" size="2"></font>

ArrayList myCompo =

<font style="font-size: x-small;" size="2"></font>new<font size="2"> ArrayList();</font>

myCompo.add(opt);

issueObject.setCustomFieldValue(customFieldcompo,myCompo);

Thankyou all!!

TAGS
AUG Leaders

Atlassian Community Events