Hi,
I'm trying to create a new issue on a project that requires a value in a Select List (multiple choices) upon creation. I made a Script Runner Dynamic Form where I ask for simple text values:
- project key
- issue type
- reporter
- summary
- Brand -> custom field Select List (multiple choices)
I create a ComponentAccessor.issueService.newIssueInputParameters() with all the parameters, but when I try for the validateCreate() method I get this error:
java.lang.AssertionError: Errors: {customfield_12914=Invalid value '[MRP]' passed for customfield 'Brand/s'. Allowed values are: 14829[TON], 15901[MRP], 15725[TCF], -1}
Here's the script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.onresolve.scriptrunner.parameters.annotation.UserPicker
import com.onresolve.scriptrunner.parameters.annotation.meta.Option
import org.apache.log4j.Logger
import org.apache.log4j.Level
import static Constants.*
// Set the logger
def lg = Logger.getLogger(getClass())
lg.setLevel(Level.DEBUG)
// Constants class
class Constants {
// Custom fields
static final int IDBrand = 12914
}
// INITIALIZATION
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
@ShortTextInput(description = "Project key e.g. JTC (mandatory)", label = "Project")
String projectKeyName
@ShortTextInput(description = "Issue Type name e.g. Bug (mandatory)", label = "Issue Type")
String issueTypeName
@UserPicker(description = "User that will be the reporter of the issue (mandatory)", label = "Reporter")
ApplicationUser reporter
@ShortTextInput(description = "Priority name e.g. Medium (optional, if empty default will be set)", label = "Priority")
String priorityName
@ShortTextInput(description = "Brand/s name e.g. TCF (depends on project & issue type)", label = "Brand/s")
String brandName
@ShortTextInput(description = "The summary for the new issue (mandatory)", label = "Summary")
String summary
@ShortTextInput(description = "The description for the new issue (optional)", label = "Description")
String description
def cFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
IssueManager issueManager = ComponentAccessor.getIssueManager()
def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKeyName)
assert project: "Could not find project with key $projectKeyName"
def issueType = constantsManager.allIssueTypeObjects.findByName(issueTypeName)
assert issueType: "Could not find issue type with name $issueTypeName"
// Reporter can't be empty
assert reporter : "Reporter can't be empty. Please select someone"
// if we cannot find the priority with the given name or if this is null, then set the default priority
def priority = constantsManager.priorities.findByName(priorityName) ?: constantsManager.defaultPriority
// Summary can't be empty
assert summary : "Summary can't be empty. Please fill it with something"
// CUSTOM FIELDS
// search for brand option
def cfBrand = cFieldManager.getCustomFieldObject(IDBrand)
def iss = issueManager.getIssueByCurrentKey("YFH-1667")
def availableOptions = ComponentAccessor.optionsManager.getOptions(cfBrand.getRelevantConfig(iss))
def optionToSet = availableOptions.findAll { it.value == brandName }
assert optionToSet: "Could not find option with value $newValue. Available options are ${availableOptions*.value}"
// set issue paramethers
def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(reporter.key)
setPriorityId(priority.id)
setSummary(summary)
setDescription(description)
addCustomFieldValue(IDBrand, optionToSet.toString())
}
def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
assert validationResult.isValid(): validationResult.errorCollection
def result = issueService.create(loggedInUser, validationResult)
assert result.isValid(): result.errorCollection
"New issue key: $result.issue.key"
The line where I get the error is Bold
Thanks,
Stefano