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.
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
}
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Manage Confluence like never before! This new learning path teaches you how to manage content, users, and permissions while optimizing user experience. Built for admins at all levels who want to confidently lead and unlock more innovative collaboration.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.