script-runner set value in a select list field

Hello,

I use script runner to create subtask on transition, with additional issues actions like following :

1
2
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'GOL Issue Type'}
issue.setCustomFieldValue(cf, 'Foundation data Workbook')

I can't make it work.

'GOL Issue Type' is a select list field, with an option label "Foundation data Workbook"

Can somebody help me to figure this out ?

Thanks

2 answers

1 accepted

7 votes
Henning Tietgens Community Champion Feb 05, 2014

Select lists need an Option object as parameter for setCustomFieldValue(). Use this to find the value for setCustomFieldValue()

import com.atlassian.jira.component.ComponentAccessor

// ...

def fieldConfig = cf.getRelevantConfig(issue)
value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Foundation data Workbook' }

Thanks a lot Henning ! The subtask is now well created but the customfield is not set to the value 'Foundation data Workbook' on the subtask.

Forget it, I didn't set the value :

issue.setCustomFieldValue(cf, value)

thanks :)

After searching for 2 days I finally found your answer Henning, and it did the trick for my problem too! Thanks so much!

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you