Forums

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

select list other add on

Jacob francois June 24, 2020

I would like to use the below script

https://scriptrunner.adaptavist.com/5.2.0/jira/recipes/behaviours/select-list-other.html

 

[

 

 

 

import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() def faveFruitOtherFld = customFieldManager.getCustomFieldObjectByName("Favourite Fruit (Other)") def issueService = ComponentAccessor.getIssueService() def issue = event.issue def otherFaveFruit = issue.getCustomFieldValue(faveFruitOtherFld) as String if (otherFaveFruit) { def faveFruitFld = customFieldManager.getCustomFieldObjectByName("Favourite Fruit") def fieldConfig = faveFruitFld.getRelevantConfig(issue) def currentOptions = optionsManager.getOptions(fieldConfig) def newSeqId = currentOptions*.sequence.max() - 1 def option = optionsManager.createOption(fieldConfig, null, newSeqId, otherFaveFruit) def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issueInputParameters = issueService.newIssueInputParameters() issueInputParameters.with { addCustomFieldValue(faveFruitFld.idAsLong, option.optionId.toString()) addCustomFieldValue(faveFruitOtherFld.idAsLong, null) } def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters) if (updateValidationResult.isValid()) { issueService.update(currentUser, updateValidationResult) } else { log.warn("Failed to update issue: ${issue.key}: ${updateValidationResult.errorCollection}") } }

 

]

to also  check that  the user-provided "other" value doesn’t actually already exist in the list.

1 answer

0 votes
Mathis Hellensberg
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.
June 29, 2020

Hi @Jacob francois 

Adding something along the line of this will let you check:

def existingOptions = optionsManager.getOptions(fieldConfig)

existingOption.each { opt ->

if (opt.getValue().toString().equals(faveFruitOtherFld.getValue(issue).toString())) {

//Do something

}

}
Jacob francois July 9, 2020 edited

@Mathis Hellensberg 

 

2020-07-09 10:15:01,945 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2020-07-09 10:15:01,947 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.manager.CachedOptionsManager.getAllOptions() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField) values: [Vendor Name]
Possible solutions: getAllOptions(), getAllOptions(), getOptions(com.atlassian.jira.issue.fields.config.FieldConfig), getOptions(com.atlassian.jira.issue.fields.config.FieldConfig)
 at Script264.run(Script264.groovy:24)


getting the below errors when trying.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events