Missed Team ’24? Catch up on announcements here.

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

How to select one of the existing value of dropwdown(single list dropdown) using groovy script

GopiR October 6, 2016

How to select one of the existing value of dropwdown(single list dropdown) using groovy script?

3 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
adammarkham
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 7, 2016

There is an example of how to select a value from a single select dropdown here using behaviours.

Essentially the server side script you want is:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def formField = getFieldByName("Single Select")

def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(formField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionToSelect = options.find {
    it.value == "The option to select here"
}
formField.setFormValue(optionToSelect.optionId)

You will need to change the field name and option to select.

1 vote
Vasiliy Zverev
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 6, 2016

Here is code exmple:

for(Option option: ComponentAccessor.getOptionsManager().getOptions(postroenie_cstFld.getRelevantConfig(issue)))
    if(option.toString().equals("option name")) {
        requaredOption = option;
        break;    
}

More details:

Options set is determinated with context, namely with project and issue type. Since it is requred to get option for some context. Then it is requred to find option wit requred name.

0 votes
GopiR October 13, 2016

Hi,

This worked Perfectly.

But how i can set dropdown value to "None" which is the initial value of dropdown

I believe formField.setFormValue(-1) should set to None.

TAGS
AUG Leaders

Atlassian Community Events