Missed Team ’24? Catch up on announcements here.

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

How can I select an option of a Customfield from type Select List programmed in my plugin

Ulrich Nack
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 28, 2011

Hi all,

I like to select a entry of a customfield from type of Select List.

Since Jira 4.4 the the way I updated the customfield didn't work any more for a Select List or Mult Select List.

{code}

final CustomFieldManager cfManager = ComponentManager
.getInstance().getCustomFieldManager();
final CustomField cf = cfManager
.getCustomFieldObjectByName(sCustomField_Name);
final IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
cf.updateValue(null, issue,
new ModifiedValue(
issue.getCustomFieldValue(cf),
oCustomField_Value),
changeHolder);
{code}

I read some articles about this behaviour, but thy handle about adding or sorting options.

But I want "only" select one existing option by programm (in a plugin).

Has someone a code snippet to demonstrate how to handle this problem?

Thanks

Uli

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
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 28, 2011

What is oCustomField_Value? Is it an Option object?

Ulrich Nack
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 28, 2011

The oCustomField_Value is java.lang.Object

public static void updateCustomField(final Issue issue,
final String sThisClass, final String sCustomField_Name,
final Object oCustomField_Value)


Should it be an Option Object?

If yes, how can I get one? And how to handle it?


Ulrich Nack
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 29, 2011

I changed the oCustomFieldValue to type "Option" and it works.

My problem was to figure out how to get the Option.

The following code-snipped shows how I solved it (I hope it can help other member of the community):

final CustomFieldManager cfm = ComponentManager.getInstance().getCustomFieldManager();
            final CustomField customField = cfm.getCustomFieldObjectByName("myCustomField");

            final OptionsManager optionsManager = ComponentAccessor
                            .getOptionsManager();
            final FieldConfig fieldConfig = customField
                            .getRelevantConfig(issue);
            final Options options = optionsManager.getOptions(fieldConfig);

            final Option oTaskTypeOption;

            String sTaskType = "mySelectListEntry";

            oTaskTypeOption = options.getOptionForValue(sTaskType, null);

            final CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager();
            final CustomField cf = cfManager.getCustomFieldObjectByName(sCustomField_Name);
            final IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
            cf.updateValue(null, issue,new ModifiedValue(issue.getCustomFieldValue(cf),oTaskType), changeHolder);

Thanks Jobin, you sent me to the right way

Uli

TAGS
AUG Leaders

Atlassian Community Events