Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update drop down select custom field

Vitalli Vintoniak August 14, 2018

Hello folks!

I trying to update drop down select custom field in Jira 7.6 and got the error. What is wrong here?

:

def cfm = ComponentAccessor.getCustomFieldManager()
def im = ComponentAccessor.getIssueManager()

MutableIssue issue = im.getIssueObject("OPS-11250")

def portfolioCF = cfm.getCustomFieldObjectsByName("Portfolio")
def portfolioCFget = issue.getCustomFieldValue(portfolioCF)
def portfolioConf = portfolioCF.getRelevantConfig(ussue)
def portfolioCfopt = ComponentAccessor.optionsManager.getOptions(portfolioConf)
log.error("Portfolio options - " + portfolioCfopt)
def value = portfolioCfopt?.find
{
it.toString() == "Some value"
}
log.error("Setting value " + value)
issue.setCustomFieldValue(portfolioCF, value)

 

No signature of method: com.google.common.collect.SingletonImmutableList.getRelevantConfig() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [OPS-11250]

groovy.lang.MissingMethodException: No signature of method: com.google.common.collect.SingletonImmutableList.getRelevantConfig() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [OPS-11250] at set_application.run(set_application.groovy:48)

 

2 answers

1 accepted

1 vote
Answer accepted
Neta Elyakim
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.
August 14, 2018

Use this:

def cf = customFieldManager.getCustomFieldObjectByName('Some Custom Field Name')
def cfConfig = cf.getRelevantConfig(issue)
def customFieldOptions = ComponentAccessor.optionsManager.getOptions(cfConfig)

def changeHolder = new DefaultIssueChangeHolder();

def fieldOption = customFieldOptions.find {it.value == "Some Value"}
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf),fieldOption),changeHolder);

Vitalli Vintoniak August 14, 2018

It works, thank you!

2 votes
Ignacio Pulgar
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.
August 14, 2018

I think that the problem relies in getCustomFieldObjectsByName() is returning a collection of custom fields, even if it has just one element:

https://docs.atlassian.com/software/jira/docs/api/7.2.6/com/atlassian/jira/issue/CustomFieldManager.html#getCustomFieldObjectsByName-java.lang.String-

So, portfolioCF is actually a collection of custom fields, and not merely the custom field you wish. May you try changing its definition to:

def portfolioCF = cfm.getCustomFieldObjectsByName("Portfolio")[0]

This way, the first element (custom field, in this case) will be returned and assigned to portfolioCF.

Assuming there's just one custom field named Portfolio, I think you'll get what you need.
Also beware of the typo in the word 'issue' here:

getRelevantConfig(ussue)

 

Vitalli Vintoniak August 14, 2018

After adding "[0]" error disappeared, but the field was not updated.

Suggest an answer

Log in or Sign up to answer