I have a scriptrunner job that creates an issue based off of a JQL query result. All of that works fine and the issue gets created. However, I want to be able to add a value to a custom field that is a radio button. I have use options manager and found the option and then use setCustomFieldValue(cf, value) and it still is not liking it. I work in an environment where i can not share my code, if anyone has any tips that would greatly be appreciated. Also, I got around it by letting the job create the issue without the custom field and then have a listener wait for the creation of the issue and then i can update the value of the custom field. This is a workaround i want to get rid of because I need to make the custom field required.
EDIT: Added code block below.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def user = ComponentsAccessor.jiraAuthentiationContext.loggedInUser
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = CompnentAccessor.issueService
def constantsManager = ComponentAccessor.contanstsManager
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def jqlSearch = "project = TEST AND created >= startOfDay(-4h)
def query = jqlQueryParser.parseQuery(jqlSearch)
def results = searchService.search(user,query,PagerFilter.getUnlimitedFilter())
if (results == null) return
final projectKey = 'TEST'
final issueTypeName = 'Test Issue'
final reporterKey = 'admin'
final summary = 'Test Entry'
final description = 'Test Description'
def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
def issueType = constantsManager.allIssueTypeObjects.findByName(issueTypeName)
def issueContext = new IssueContextImpl(project, issueType) as IssueContext
def reporter = ComponentAccessor.userManager.getUSerByKey(reporterKey) ?: user
def cf = customFieldManager.getCustomFieldObject("customfield_10902")
def fieldConfig = cf.getRelevantConfig(issueContext)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
def issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(project.id)
issueInputParameters.setIssueTypeId(issueType.id)
issueInputParameters.setReporterId(reporter.name)
issueInputParameters.setSummary(summary)
issueInputParameters.setDescription(description)
issueInputParameters.setCustomFieldValue("customfield_10902", option)
//issueInputParameters.addCustomFieldValue("customfield_10902", option)
//issueInputParameters.setCustomFieldValue("customfield_10902", "Yes")
def validationResult = issueService.validateCreate(user, issueInputParameters)
def result = issueService.create(user, validationResult)
return