Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.

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.

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you